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

InputText: It doesn't take classNames when unstyled is true #6274

Closed
mevlutcantuna opened this issue Apr 1, 2024 · 10 comments · Fixed by #6323
Closed

InputText: It doesn't take classNames when unstyled is true #6274

mevlutcantuna opened this issue Apr 1, 2024 · 10 comments · Fixed by #6323
Assignees
Labels
Component: Unstyled Issue related to unstyled/passthrough attributes Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@mevlutcantuna
Copy link

Describe the bug

InputText doesn't take given classNames when unstyled prop is true

Reproducer

https://stackblitz.com/edit/kuem11?file=src%2FApp.jsx,package.json

PrimeReact version

10.6.2

React version

18.x

Language

TypeScript

Build / Runtime

Create React App (CRA)

Browser(s)

Chrome

Steps to reproduce the behavior

  1. Pass unstyled prop to InputText
  2. Give it a className
  3. Check it has or not className

Expected behavior

It must take given classNames, but remove initial classNames that come from prime

@mevlutcantuna mevlutcantuna added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Apr 1, 2024
@melloware melloware added Component: Unstyled Issue related to unstyled/passthrough attributes and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Apr 1, 2024
@melloware
Copy link
Member

melloware commented Apr 1, 2024

i thought in unstyled mode you were supposed to use PT?

See: https://stackblitz.com/edit/kuem11-ajcwbr?file=src%2FApp.jsx

@melloware melloware added the Resolution: Workaround Issue or pull request contains a workaround. It needs to be reviewed further by Core Team label Apr 1, 2024
@mevlutcantuna
Copy link
Author

@melloware okay. I am using unstyled mode to remove initial class names like other component

@melloware
Copy link
Member

i will leave this open as I am not sure but at least you have a workaround!

@mevlutcantuna
Copy link
Author

mevlutcantuna commented Apr 1, 2024

will every component be like this now?

@melloware
Copy link
Member

Not sure i will let Primetek chime in. I assigned this to them.

@peconomou929
Copy link
Contributor

This is also a problem I experienced.

Imagine you want to build a reusable component like a button, call it MyButton (see the code snippet below). To do this you use an unstyled PrimeReact Button, and give it your custom pass through options. In order to abstract away these modifications, you wrap it in a component which "forwards" its props to PrimeReact Button.

import { Button, ButtonProps } from 'primereact/button'

export function MyButton(props: ButtonProps) {
    return <Button {...props} unstyled pt={myButtonPTOptions} />
}

Now, say I want to create a MyButton with a left margin. If am using Tailwind, I might try something like <MyButton className="ml-2"/>, but, for the reasons mentioned in this issue, this will not work, as the class name gets thrown away in unstyled mode.

There are of course work-arounds, such as

  • using the style property instead of the className property
  • adding custom login inside the pass-through options object which "reads" the className attribute, and appends those class names to the root element class name list.

But...it would be nice if PrimeReact just took care of this properly. The expected behaviour would be that the unstyled tag simply remove PrimeReact class names, such as p-component, p-button, etc. and doesn't remove any other class names.

@melloware
Copy link
Member

Agreed this is unexpected behavior.

@mertsincan mertsincan added Type: Bug Issue contains a defect related to a specific component. and removed Resolution: Workaround Issue or pull request contains a workaround. It needs to be reviewed further by Core Team labels Apr 8, 2024
@gucal gucal added this to the 10.6.3 milestone Apr 8, 2024
gucal added a commit to gucal/primereact that referenced this issue Apr 8, 2024
gucal added a commit that referenced this issue Apr 8, 2024
#6274 - InputText: It doesnt take classNames when unstyled is true
@peconomou929
Copy link
Contributor

Thanks for the PR!

Seems to fix it for the input text, but there are still some other components which suffer the same exact bug, e.g. the tab menu. Should we consider that part of this issue and keep this one open?

@melloware
Copy link
Member

I would create a new issue please and just use the bullet list feature of GitHub to list the components that have the issue!

@peconomou929
Copy link
Contributor

Done. Please see this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Unstyled Issue related to unstyled/passthrough attributes Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants