Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Components
import { VMenu } from '..'
import { VList, VListItem } from '@/components/VList'

// Utilities
import { render, screen, userEvent, wait } from '@test'

describe('VMenu', () => {
it('returns focus to activator on Escape', async () => {
render(() => (
<div>
<button data-testid="activator">Open menu</button>
<VMenu activator="[data-testid='activator']">
<VList>
<VListItem title="Item 1" />
<VListItem title="Item 2" />
</VList>
</VMenu>
</div>
))

const activator = screen.getByTestId('activator')
await userEvent.click(activator)
// Wait for globalTop setTimeout in useStack to fire
await wait()

// Menu should be open
const item1 = screen.getByText('Item 1')
expect(item1).toBeVisible()

// Press Escape to close
await userEvent.keyboard('{Escape}')

// Menu should be closed
expect(item1).not.toBeVisible()

Check failure on line 35 in packages/vuetify/src/components/VMenu/__tests__/VMenu.spec.browser.tsx

View workflow job for this annotation

GitHub Actions / Test

components/VMenu/__tests__/VMenu.spec.browser.tsx > VMenu > returns focus to activator on Escape

Error: expect(element).not.toBeVisible() Received element is visible: <div class="v-list-item-title" /> ❯ toBeVisible components/VMenu/__tests__/VMenu.spec.browser.tsx:35:22

// Focus should have returned to the activator button
expect(document.activeElement).toBe(activator)
})
})
4 changes: 1 addition & 3 deletions packages/vuetify/src/components/VOverlay/VOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,7 @@ export const VOverlay = genericComponent<OverlaySlots>()({
}
if (!props.persistent) {
isActive.value = false
if (contentEl.value?.contains(document.activeElement)) {
activatorEl.value?.focus()
}
activatorEl.value?.focus()
} else animateClick()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1027,5 +1027,15 @@ describe('VSelect', () => {
expect(screen.getByCSS('.v-select .v-field')).not.toHaveClass('v-field--focused')
})

// https://github.com/vuetifyjs/vuetify/issues/22730
it('should pass title attribute to the root element', async () => {
const { element } = render(() => (
<VSelect title="Select a state" items={['California', 'Colorado']} />
))

expect(element).toHaveAttribute('title', 'Select a state')
expect(element.querySelector('input')).not.toHaveAttribute('title')
})

showcase({ stories })
})
2 changes: 1 addition & 1 deletion packages/vuetify/src/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export function isComposingIgnoreKey (e: KeyboardEvent): boolean {
export function filterInputAttrs (attrs: Record<string, unknown>) {
const [events, props] = pickWithRest(attrs, [onRE])
const inputEvents = omit(events, bubblingEvents)
const [rootAttrs, inputAttrs] = pickWithRest(props, ['class', 'style', 'id', 'inert', /^data-/])
const [rootAttrs, inputAttrs] = pickWithRest(props, ['class', 'style', 'id', 'inert', 'title', /^data-/])
Object.assign(rootAttrs, events)
Object.assign(inputAttrs, inputEvents)
return [rootAttrs, inputAttrs]
Expand Down
Loading