primefaces / primevue

Next Generation Vue UI Component Library
https://primevue.org
MIT License
9.15k stars 1.12k forks source link

InputMask: Passed props are not set #6025

Closed SwitzerChees closed 1 week ago

SwitzerChees commented 3 weeks ago

Describe the bug

Properties like id or name are not passed through anymore to the native rendered input of type text. The problem can be reproduced or seen directly in the official documentation: V4 Documentation (https://primevue.org/inputmask/):

<div class="flex-auto">
    <label for="phone" class="font-bold block mb-2">Phone</label>
    <InputMask id="phone" v-model="value2" mask="(999) 999-9999" placeholder="(999) 999-9999" fluid />
</div>

The rendered native input element is missing the id="phone" prop: image

V3 Documentation (https://v3.primevue.org/inputmask/):

<div class="flex-auto">
    <label for="phone" class="font-bold block mb-2">Phone</label>
    <InputMask id="phone" v-model="value2" mask="(999) 999-9999" placeholder="(999) 999-9999" />
</div>

The rendered native input element has the id="phone" prop: image

This problem not only exists on the official documentation website but also when I use the component directly in my own application.

Reproducer

https://stackblitz.com/edit/primevue-4-vite-issue-template-yzbded?file=src%2FApp.vue

PrimeVue version

4.0.0

Vue version

4.x

Language

TypeScript

Build / Runtime

Nuxt

Browser(s)

No response

Steps to reproduce the behavior

  1. use InputMask component

  2. define id or name property in the input mask image

  3. check the rendered html output and check if they are missing. image

Expected behavior

The same behaviour like on V3 and as described in the following part of the documentation (https://primevue.org/inputmask/#accessibility):

InputMask component renders a native input element that implicitly includes any passed prop.

mertsincan commented 3 weeks ago

Interesting! Do you get an error on console?

SwitzerChees commented 3 weeks ago

No there are no errors in the console, not on the official documentation page (https://primevue.org/inputmask/) and also not in my own application when I use the InputMask.

Back in V3 a native input element was used with v-bind: https://github.com/primefaces/primevue/blob/v3-prod/components/lib/inputmask/InputMask.vue image

Now in the V4 there is now the :pt used from the InputText component: https://github.com/primefaces/primevue/blob/master/packages/primevue/src/inputmask/InputMask.vue image and props like placeholder and class have their own props now.

maybe something in the passthrough logic doesn't work as expected?

mertsincan commented 3 weeks ago

Thanks a lot! We'll fix it in the next version.

vanpyrzericj commented 1 week ago

Just want to add onto this that being able to pass the type attribute (which we can do for <InputText>) would also be ideal, in addition to the OP's attributes.

This is helpful when, for example, an input mask of a phone number is added, where we want to set type="tel" for mobile keyboards to display the numeric keypad.

tugcekucukoglu commented 1 week ago

New pt usage of InputMask:

<InputMask
            :pt="{
                pcInputText: {
                    root: 'className'
                }
            }"
        />
luke-z commented 1 week ago

@tugcekucukoglu Isn't it a bit of an anti-pattern to place the id property inside a passthrough property instead of directly on the custom HTML element, which adds it to the input element?

SwitzerChees commented 1 week ago

That doesn't resolve the issue. Please check on your OWN documentation page the error remains even on your own page: https://primevue.org/inputmask/#mask

image

And the rendered native input element doesn't have the id anymore.

image

If there is now a way to pass through attributes with PT then it would also make sense to update your own documentation ;-).

tugcekucukoglu commented 6 days ago

@luke-z agree with you.

@SwitzerChees id property problem is obvious and there is no link with pt property.

Could you create an issue about this defect? I can fix it for the next version.

SamuelWei commented 5 days ago

@SwitzerChees I copied most of this issue and create a new one as @tugcekucukoglu asked for: https://github.com/primefaces/primevue/issues/6100

SwitzerChees commented 5 days ago

@SamuelWei that's great thank you 👍🏼