-
Notifications
You must be signed in to change notification settings - Fork 535
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
Refine 'as' prop type in button component and fix name of aria type #2659
Conversation
🦋 Changeset detectedLatest commit: 7f32cfc The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
size-limit report 📦
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thanks for doing this 🙏
Just left one comment, I think it might be the convention in PRC but I'm not 100% sure 😅
I think all that's left after the comment is to add a changeset and should be good to go 👍
Did you submit the comment? 😅 I am not seeing it on my end. Also, would this be a patch? |
src/Button/ButtonBase.tsx
Outdated
@@ -18,6 +19,7 @@ const trailingIconStyles = { | |||
const ButtonBase = forwardRef<HTMLElement, ButtonProps>( | |||
({children, as: Component = 'button', sx: sxProp = defaultSxProp, ...props}, forwardedRef): JSX.Element => { | |||
const {leadingIcon: LeadingIcon, trailingIcon: TrailingIcon, variant = 'default', size = 'medium', ...rest} = props | |||
const innerRef = React.useRef<HTMLElement>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const innerRef = React.useRef<HTMLElement>() | |
const innerRef = React.useRef<HTMLElement>() | |
useRefObjectAsForwardedRef(forwardedRef, innerRef) |
Here was that convention that I was talking about! This should be available in src/hooks/useRefObjectAsForwardedRef.ts
. This seems to show up in a couple components that both have a local and forwardedRef
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AMAZING thank you!
@kendallgassner sorry about that! Just left a comment above 👍 And good question about |
Co-authored-by: Josh Black <joshblack@github.com>
…om/primer/react into kendallg/limit-button-as-prop-type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this!
React.useEffect(() => { | ||
if (!(innerRef.current instanceof HTMLButtonElement) && !(innerRef.current instanceof HTMLAnchorElement)) { | ||
if (__DEV__) { | ||
// eslint-disable-next-line no-console | ||
console.warn('This component should be an instanceof a semantic button or anchor') | ||
} | ||
} | ||
}, [innerRef]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
realize this might be a little late, but should we wrap the entire effect in
if (DEV) {}
I realize that'll trip the linter, but since it's not actually conditional but instead a build time flag, I think that's worth the lint disable, which would strip a few extra bytes from production builds, and cause no actual runtime issues?
Otherwise, we'll end up still doing instanceof checks here, for no reason on every mount?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened a PR for this suggestion - #2666
Describe your changes here.
aria-labelby
->aria-labelledby
(aria-labelby is not an aria attribute)<a>
or<button>
I introduced the library react-merge-refs to do this but please let me know if there is a better way 😸
Open Questions
Should this be a patch? Since its a new warning message?
Screenshots
Please provide before/after screenshots for any visual changes
Merge checklist
Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.