-
-
Notifications
You must be signed in to change notification settings - Fork 259
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
[Bug]: PinInput placeholders not displayed after reset value #1516
Comments
Okay, I found the cause of the issue. It is caused by function handleFocus(event: FocusEvent) {
const target = event.target as HTMLInputElement
target.setSelectionRange(1, 1)
if (!target.value)
target.placeholder = ''
} When an user focus the input, placeholder attribute is set to empty string, and only revert to its initial value (given in function handleBlur(event: FocusEvent) {
const target = event.target as HTMLInputElement
nextTick(() => {
if (!target.value)
target.placeholder = context.placeholder.value
})
} But the placeholder is never restored when pin value is cleared programmatically like just I understand why this was done that way: hide the placeholder when user focus the input and they are ready to types a character. I can see this behaviour in different pin input component across different ui library. I also see that sometimes placeholder is kept and not hidden (eg: in Disney+ for profile pin code). So IMO this behaviour should be an opt-in option. |
After resetting the component, the cursor did not return to the first input box. Is there any way to focus on the first box? |
Yes you can, you have to save ref to all digit inputs: <script lang="ts" setup>
const inputs = ref<ComponentPublicInstance[]>([])
const pin = ref<string[]>([])
const focusDigit = (index: number) => {
inputs.value[index]?.$el.focus()
}
const reset = () => {
pin.value = []
focusDigit(0)
}
</script>
<template>
<PinInputRoot
class="flex gap-2 items-center mt-8 !w-fit"
v-model="pin"
>
<PinInputInput
v-for="(id, index) in 4"
:ref="
el => {
if (el && '$el' in el) {
inputs[index] = el
}
}
"
:key="id"
:index="index"
/>
</PinInputRoot>
<button @click="reset">reset</button>
</template> |
Environment
Link to minimal reproduction
https://stackblitz.com/edit/nuxt-starter-nzrqbxnu?file=app.vue,package.json
Steps to reproduce
Describe the bug
PinInputInput
placeholders are not displayed anymore after resettingPinInputRoot
value with[]
.I also tried to set values like
['', '', '', '']
, but the same behaviour happened.Minimal code reproduction:
Expected behavior
Placeholders should be displayed.
Context & Screenshots (if applicable)
The text was updated successfully, but these errors were encountered: