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

Ask for elementType on FieldError to structure a FieldError with <p> #7525

Closed
mw10013 opened this issue Dec 16, 2024 · 2 comments
Closed

Ask for elementType on FieldError to structure a FieldError with <p> #7525

mw10013 opened this issue Dec 16, 2024 · 2 comments

Comments

@mw10013
Copy link

mw10013 commented Dec 16, 2024

Provide a general summary of the feature here

Ask for elementType on FieldError to structure a FieldError with <p> instead of <span>, which seems to be the default.

FieldError seems to call Text internally. (https://github.com/adobe/react-spectrum/blob/main/packages/react-aria-components/src/FieldError.tsx). While Text seems to have an elementType property, FieldError does not.

🤔 Expected Behavior?

Desired way to structure FieldError with <p>.

export function OuiFieldError({className, ...props}: FieldErrorProps) {
  return (
      <FieldError
        elementType="p"
        {...props}
        className={composeTailwindRenderProps(
          className,
          'text-[0.8rem] font-medium text-destructive'
        )}
      />
  )
}

😯 Current Behavior

My clumsy implementation to structure a FieldError with <p> along with guard for empty <p>'s.

export function OuiFieldError({ className, ...props }: FieldErrorProps) {
  // FieldError seems to structure with a <span> and does not have elementType like Text.
  // Wrap with <p> to get closer to shadcn.
  // Guard with validation check to prevent empty <p>'s.
  // Reference: https://github.com/adobe/react-spectrum/issues/7525
  const validation = useContext(FieldErrorContext)
  if (!validation?.isInvalid) {
    return null
  }
  return (
    <p>
      <FieldError
        {...props}
        className={composeTailwindRenderProps(
          className,
          'text-[0.8rem] font-medium text-destructive'
        )}
      />
    </p>
  )
}

💁 Possible Solution

No response

🔦 Context

Use case for this ask is simpler implementation for composing rac with shadcn.

💻 Examples

No response

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

@mw10013
Copy link
Author

mw10013 commented Dec 17, 2024

TextContext can provide the elementType to Text. Still would prefer elementType on FieldError but this certainly works.

export function OuiFieldError({ className, ...props }: FieldErrorProps) {
  return (
    <TextContext.Provider value={{ elementType: 'p' }}>
      <FieldError
        {...props}
        className={composeTailwindRenderProps(
          className,
          'text-[0.8rem] font-medium text-destructive'
        )}
      />
    </TextContext.Provider>
  )
}

@snowystinger
Copy link
Member

Closing as not planned, see #5476 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants