Skip to content
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

Pass Through: Set data-testid, etc. for input's DOM element, etc. #4676

Closed
ryoku4 opened this issue Jul 21, 2023 · 2 comments · Fixed by #4677
Closed

Pass Through: Set data-testid, etc. for input's DOM element, etc. #4676

ryoku4 opened this issue Jul 21, 2023 · 2 comments · Fixed by #4677
Assignees
Labels
Typescript Issue or pull request is *only* related to TypeScript definition
Milestone

Comments

@ryoku4
Copy link

ryoku4 commented Jul 21, 2023

Describe the feature you would like to see added

My project uses PrimeReact and e2e testing (Cypress).
I would like to be able to set data-testid, data-cy, etc. using the "pass through (pt)"

<Password
  value={value}
  feedback={false}
  pt={{
    input: { "data-testid": "password-input" },
  }}
  onChange={(e) => setValue(e.target.value)}
/>

Is your feature request related to a problem?

Attempting to set the above will result a type error.

image

No overload matches this call.
Overload 1 of 2, '(props: PasswordProps | Readonly): Password', gave the following error.
Type '{ "data-testid": string; }' is not assignable to type 'PasswordPassThroughType<HTMLAttributes>'.
Object literal may only specify known properties, and '"data-testid"' does not exist in type 'HTMLAttributes | ((options?: PasswordPassThroughMethodOptions | undefined) => void | HTMLAttributes<...>)'.
Overload 2 of 2, '(props: PasswordProps, context: any): Password', gave the following error.
Type '{ "data-testid": string; }' is not assignable to type 'PasswordPassThroughType<HTMLAttributes>'.
Object literal may only specify known properties, and '"data-testid"' does not exist in type 'HTMLAttributes | ((options?: PasswordPassThroughMethodOptions | undefined) => void | HTMLAttributes<...>)'.ts(2769)

Describe the solution you'd like

I would like to be able to set data-testid, data-cy, etc. using the "pass through (pt)" without causing a type error

Describe alternatives you have considered

I tried to set data-testid in the "password component" like below, without using the "pass through (pt)", however it caused data-testid split into two elements (div and input).

Password Component

<Password
  value={value}
  feedback={false}
  data-testid="password-input"
  onChange={(e) => setValue(e.target.value)}
/>

div and input

<div
  class="p-password p-component p-inputwrapper"
  value=""
  data-testid="password-input"
  data-pc-name="password"
  data-pc-section="root"
>
  <input
    class="p-inputtext p-component p-password-input p-password-input"
    data-testid="password-input"
    type="password"
    data-pc-section="root"
    data-pc-name="inputtext"
    value=""
  />
</div>

Additional context

No response

@ryoku4 ryoku4 added Status: Discussion Issue or pull request needs to be discussed by Core Team Type: New Feature Issue contains a new feature or new component request labels Jul 21, 2023
@github-actions github-actions bot added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Jul 21, 2023
@melloware
Copy link
Member

Totally agree @ryoku4 let me look as I know how extremely important things like Cypress and Playwright testing can be.

@melloware melloware added Typescript Issue or pull request is *only* related to TypeScript definition and removed Type: New Feature Issue contains a new feature or new component request Status: Discussion Issue or pull request needs to be discussed by Core Team Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Jul 21, 2023
@melloware melloware self-assigned this Jul 21, 2023
@melloware melloware added this to the 9.6.1 milestone Jul 21, 2023
melloware added a commit to melloware/primereact that referenced this issue Jul 21, 2023
@ryoku4 ryoku4 changed the title Pass Through: Set data-testid, etc. for input's DOM element, etc. Pass Through: Set data-testid, etc. for input's DOM element, etc. Jul 21, 2023
@ryoku4
Copy link
Author

ryoku4 commented Jul 21, 2023

Thank you for the quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Typescript Issue or pull request is *only* related to TypeScript definition
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants