mirror of
https://github.com/nasa/openmct.git
synced 2025-05-29 21:54:20 +00:00
Merge pull request #2518 from nasa/modal-improvement
WIP: Modal improvement
This commit is contained in:
commit
6e2497461a
@ -8,12 +8,15 @@
|
|||||||
v-if="dismissable"
|
v-if="dismissable"
|
||||||
@click="destroy">
|
@click="destroy">
|
||||||
</button>
|
</button>
|
||||||
<div class="c-overlay__contents" ref="element"></div>
|
<div class="c-overlay__contents" ref="element" tabindex="0"></div>
|
||||||
<div class="c-overlay__button-bar" v-if="buttons">
|
<div class="c-overlay__button-bar" v-if="buttons">
|
||||||
<button class="c-button"
|
<button class="c-button"
|
||||||
|
tabindex="0"
|
||||||
|
ref="buttons"
|
||||||
v-for="(button, index) in buttons"
|
v-for="(button, index) in buttons"
|
||||||
:key="index"
|
:key="index"
|
||||||
:class="{'c-button--major': button.emphasis}"
|
@focus="focusIndex=index"
|
||||||
|
:class="{'c-button--major': focusIndex===index}"
|
||||||
@click="buttonClickHandler(button.callback)">
|
@click="buttonClickHandler(button.callback)">
|
||||||
{{button.label}}
|
{{button.label}}
|
||||||
</button>
|
</button>
|
||||||
@ -69,6 +72,7 @@
|
|||||||
flex: 1 1 auto;
|
flex: 1 1 auto;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
outline: none;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,9 +175,17 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
|
data: function () {
|
||||||
|
return {
|
||||||
|
focusIndex: -1
|
||||||
|
};
|
||||||
|
},
|
||||||
inject: ['dismiss', 'element', 'buttons', 'dismissable'],
|
inject: ['dismiss', 'element', 'buttons', 'dismissable'],
|
||||||
mounted() {
|
mounted() {
|
||||||
this.$refs.element.appendChild(this.element);
|
this.$refs.element.appendChild(this.element);
|
||||||
|
setTimeout(() => {
|
||||||
|
this.getElementForFocus().focus();
|
||||||
|
}, 0);
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
destroy: function () {
|
destroy: function () {
|
||||||
@ -184,6 +196,25 @@
|
|||||||
buttonClickHandler: function (method) {
|
buttonClickHandler: function (method) {
|
||||||
method();
|
method();
|
||||||
this.$emit('destroy');
|
this.$emit('destroy');
|
||||||
|
},
|
||||||
|
getElementForFocus: function () {
|
||||||
|
const defaultElement = this.$refs.element;;
|
||||||
|
if (!this.$refs.buttons) {
|
||||||
|
return defaultElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
const focusButton = this.$refs.buttons.filter((button, index) => {
|
||||||
|
if (this.buttons[index].emphasis) {
|
||||||
|
this.focusIndex = index;
|
||||||
|
}
|
||||||
|
return this.buttons[index].emphasis;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!focusButton.length) {
|
||||||
|
return defaultElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
return focusButton[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user