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

Refine 'as' prop type in button component and fix name of aria type #2659

Merged
merged 12 commits into from
Dec 7, 2022

Conversation

kendallgassner
Copy link
Contributor

@kendallgassner kendallgassner commented Dec 6, 2022

Describe your changes here.

  • aria-labelby -> aria-labelledby (aria-labelby is not an aria attribute)
  • restrict the button 'as' prop at runtime to be either a semantic <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

  • Added/updated tests
  • Added/updated documentation
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

@kendallgassner kendallgassner requested review from a team and broccolinisoup December 6, 2022 20:50
@changeset-bot
Copy link

changeset-bot bot commented Dec 6, 2022

🦋 Changeset detected

Latest commit: 7f32cfc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

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

@kendallgassner kendallgassner temporarily deployed to github-pages December 6, 2022 20:55 Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-2659 December 6, 2022 20:56 Inactive
@github-actions
Copy link
Contributor

github-actions bot commented Dec 6, 2022

size-limit report 📦

Path Size
dist/browser.esm.js 82.8 KB (+0.06% 🔺)
dist/browser.umd.js 83.45 KB (+0.06% 🔺)

@kendallgassner kendallgassner temporarily deployed to github-pages December 6, 2022 21:02 Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-2659 December 6, 2022 21:02 Inactive
@kendallgassner kendallgassner temporarily deployed to github-pages December 6, 2022 21:13 Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-2659 December 6, 2022 21:13 Inactive
@joshblack joshblack added the 💓collab a vibrant hub of collaboration label Dec 6, 2022
Copy link
Member

@joshblack joshblack left a 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 👍

@kendallgassner
Copy link
Contributor Author

@joshblack

Just left one comment, I think it might be the convention in PRC but I'm not 100% sure 😅

Did you submit the comment? 😅 I am not seeing it on my end.

Also, would this be a patch?

@kendallgassner kendallgassner temporarily deployed to github-pages December 6, 2022 23:25 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-2659 December 6, 2022 23:26 Inactive
@@ -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>()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AMAZING thank you!

@joshblack
Copy link
Member

@kendallgassner sorry about that! Just left a comment above 👍 And good question about patch versus minor, I think regardless it will be included in the next minor so what you have currently in the changeset should totally work.

@github-actions github-actions bot temporarily deployed to storybook-preview-2659 December 7, 2022 17:58 Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-2659 December 7, 2022 18:01 Inactive
@kendallgassner kendallgassner temporarily deployed to github-pages December 7, 2022 18:02 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-2659 December 7, 2022 18:02 Inactive
src/Button/ButtonBase.tsx Outdated Show resolved Hide resolved
Co-authored-by: Josh Black <joshblack@github.com>
@kendallgassner kendallgassner temporarily deployed to github-pages December 7, 2022 18:43 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-2659 December 7, 2022 18:44 Inactive
@kendallgassner kendallgassner temporarily deployed to github-pages December 7, 2022 18:59 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-2659 December 7, 2022 18:59 Inactive
Copy link
Member

@joshblack joshblack left a 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!

@joshblack joshblack merged commit 84d2997 into main Dec 7, 2022
@joshblack joshblack deleted the kendallg/limit-button-as-prop-type branch December 7, 2022 21:10
@primer-css primer-css mentioned this pull request Dec 7, 2022
Comment on lines +34 to +42
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])

Copy link
Collaborator

@mattcosta7 mattcosta7 Dec 8, 2022

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?

Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a11y-eng-secondary 💓collab a vibrant hub of collaboration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants