Skip to content

Commit 19fc56a

Browse files
committed
fix(VDialog): focus on internal content when shown
1 parent 9e2edf3 commit 19fc56a

File tree

4 files changed

+24
-25
lines changed

4 files changed

+24
-25
lines changed

Diff for: packages/vuetify/src/components/VDialog/VDialog.sass

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
transition: .3s map-get($transition, 'fast-in-fast-out')
1010
width: 100%
1111
z-index: inherit
12+
outline: none
1213
+elevation($dialog-elevation)
1314

1415
&:not(.v-dialog--fullscreen)
@@ -46,7 +47,6 @@
4647
transition: .2s map-get($transition, 'fast-in-fast-out'), z-index 1ms
4748
width: 100%
4849
z-index: 6
49-
outline: none
5050

5151
.v-dialog__container
5252
display: none

Diff for: packages/vuetify/src/components/VDialog/VDialog.ts

+14-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Toggleable from '../../mixins/toggleable'
1717
import ClickOutside from '../../directives/click-outside'
1818

1919
// Helpers
20-
import mixins from '../../util/mixins'
20+
import mixins, { ExtractVue } from '../../util/mixins'
2121
import { removed } from '../../util/console'
2222
import {
2323
convertToUnit,
@@ -37,8 +37,15 @@ const baseMixins = mixins(
3737
Toggleable
3838
)
3939

40+
interface options extends ExtractVue<typeof baseMixins> {
41+
$refs: {
42+
dialog: HTMLElement
43+
content: HTMLElement
44+
}
45+
}
46+
4047
/* @vue/component */
41-
export default baseMixins.extend({
48+
export default baseMixins.extend<options>().extend({
4249
name: 'v-dialog',
4350

4451
directives: { ClickOutside },
@@ -181,9 +188,9 @@ export default baseMixins.extend({
181188
// Double nextTick to wait for lazy content to be generated
182189
this.$nextTick(() => {
183190
this.$nextTick(() => {
184-
if (!this.$refs.content.contains(document.activeElement)) {
191+
if (!this.$refs.dialog.contains(document.activeElement)) {
185192
this.previousActiveElement = document.activeElement as HTMLElement
186-
this.$refs.content.focus()
193+
this.$refs.dialog.focus()
187194
}
188195
this.bind()
189196
})
@@ -254,7 +261,6 @@ export default baseMixins.extend({
254261
class: this.contentClasses,
255262
attrs: {
256263
role: 'document',
257-
tabindex: this.isActive ? 0 : undefined,
258264
...this.getScopeIdAttrs(),
259265
},
260266
on: { keydown: this.onKeydown },
@@ -280,6 +286,9 @@ export default baseMixins.extend({
280286
genInnerContent () {
281287
const data: VNodeData = {
282288
class: this.classes,
289+
attrs: {
290+
tabindex: this.isActive ? 0 : undefined,
291+
},
283292
ref: 'dialog',
284293
directives: [
285294
{

Diff for: packages/vuetify/src/components/VDialog/__tests__/VDialog.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -308,15 +308,15 @@ describe('VDialog.ts', () => {
308308
propsData: { eager: true },
309309
})
310310

311-
const content = wrapper.find('.v-dialog__content')
311+
const dialog = wrapper.find('.v-dialog')
312312

313-
expect(content.html()).toMatchSnapshot()
314-
expect(content.element.tabIndex).toBe(-1)
313+
expect(dialog.html()).toMatchSnapshot()
314+
expect(dialog.element.tabIndex).toBe(-1)
315315

316316
wrapper.setData({ isActive: true })
317317

318-
expect(content.element.tabIndex).toBe(0)
319-
expect(content.html()).toMatchSnapshot()
318+
expect(dialog.element.tabIndex).toBe(0)
319+
expect(dialog.html()).toMatchSnapshot()
320320
})
321321

322322
// https://github.com/vuetifyjs/vuetify/issues/8697

Diff for: packages/vuetify/src/components/VDialog/__tests__/__snapshots__/VDialog.spec.ts.snap

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,17 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`VDialog.ts should only set tabindex if active 1`] = `
4-
<div role="document"
5-
class="v-dialog__content"
6-
style="z-index: 0;"
4+
<div class="v-dialog"
5+
style="transform-origin: center center; display: none;"
76
>
8-
<div class="v-dialog"
9-
style="transform-origin: center center; display: none;"
10-
>
11-
</div>
127
</div>
138
`;
149

1510
exports[`VDialog.ts should only set tabindex if active 2`] = `
16-
<div role="document"
17-
class="v-dialog__content v-dialog__content--active"
18-
style="z-index: 202; z-index: 202;"
11+
<div class="v-dialog v-dialog--active"
12+
style="transform-origin: center center;"
1913
tabindex="0"
2014
>
21-
<div class="v-dialog v-dialog--active"
22-
style="transform-origin: center center;"
23-
>
24-
</div>
2515
</div>
2616
`;
2717

0 commit comments

Comments
 (0)