Skip to content

fix(VDateInput): accept value when picker is hidden #21273

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 0 additions & 2 deletions packages/vuetify/src/labs/VDateInput/VDateInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ export const VDateInput = genericComponent<VDateInputSlots>()({

if (!menu.value || !isFocused.value) {
menu.value = true

return
}

const target = e.target as HTMLInputElement
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Components
import { VDateInput } from '../VDateInput'

// Utilities
import { commands, render, screen, userEvent } from '@test'
import { ref } from 'vue'

describe('VDateInput', () => {
it('accepts keyboard input even if the picker is hidden', async () => {
const model = ref<Date | null>(null)
const { element } = render(() => <VDateInput v-model={ model.value } />)

await userEvent.click(element)
await commands.waitStable('.v-picker')
expect(screen.getByCSS('.v-picker')).toBeVisible()

await userEvent.keyboard('{Escape}') // hide picker, but keep the focus

await commands.waitStable('.v-picker')
expect(screen.getByCSS('.v-picker')).not.toBeVisible()

const input = screen.getByCSS('input') as HTMLInputElement
await userEvent.type(input, '02/20/2022{Enter}')

expect(model.value).toBeDefined()
const formatter = new Intl.DateTimeFormat('en-US', { dateStyle: 'medium' })
expect(formatter.format(model.value!)).toBe('Feb 20, 2022')
})
})