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

Add button focus styles #2007

Merged
merged 5 commits into from
Apr 8, 2022
Merged

Add button focus styles #2007

merged 5 commits into from
Apr 8, 2022

Conversation

pksjce
Copy link
Collaborator

@pksjce pksjce commented Mar 31, 2022

In anticipation of Buttons accessibility review, I'm pulling in changes from https://github.com/primer/css/pull/1744/files for button specific focus.

My reference is to the focus styles in this storybook.
https://primer-css-eyj5rcc1n-primer.vercel.app/css/storybook?path=/story/patterns-focusstyles--focus-styles

The main change is to remove focus styles of box-shadow and substitute it with outline. primary variant of the button gets some special treatment but all others have same focus styles.

Before

image

After

image

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.

@pksjce pksjce requested review from a team and siddharthkp March 31, 2022 08:35
@changeset-bot
Copy link

changeset-bot bot commented Mar 31, 2022

🦋 Changeset detected

Latest commit: 2f436be

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

@pksjce
Copy link
Collaborator Author

pksjce commented Mar 31, 2022

I am more confused about focus-visible in Safari. I can't seem to enable tabbing there, there's no experimental feature and there is no pseudoclass for it in the developer tools.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 31, 2022

size-limit report 📦

Path Size
dist/browser.esm.js 65.75 KB (+0.06% 🔺)
dist/browser.umd.js 66.15 KB (+0.05% 🔺)

Copy link
Contributor

@langermank langermank left a comment

Choose a reason for hiding this comment

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

This looks great! The only thing I'm noticing (and I can't find it in your PR for some reason) is the box-shadow being removed for :focus fallback. I had to do that in dotcom as an override, but it shouldn't be needed here 😄

css for fallback focus styles

@langermank
Copy link
Contributor

I am more confused about focus-visible in Safari. I can't seem to enable tabbing there, there's no experimental feature and there is no pseudoclass for it in the developer tools.

Hmm, I seem to have it as experimental in Safari 15.4

safari settings

@colebemis
Copy link
Contributor

The focus style for the primary button doesn't seem to fit with the rest of them. Is this intentional? cc @langermank

CleanShot 2022-03-31 at 09 23 17@2x

...fallbackFocus,
'&:focus-visible:not([disabled])': {
outline: '2px solid',
outlineOffset: '0',
Copy link
Contributor

Choose a reason for hiding this comment

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

@colebemis great catch on the primary style! This code reflects what I've done in PCSS, but I don't think its correct. I can't remember why I didn't negative offset the primary 😅 anyways.. let's try:

outlineOffset: '-2'
boxShadow: 'inset 0 0 0 3px'

That should align better. I'll make that same change in PCSS/dotcom

buttons focused

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah! I saw the difference in your code too and thought that was the spec. There was no other reference other than what you had done. Thanks for the clarification. :) Will make this change.

@pksjce
Copy link
Collaborator Author

pksjce commented Apr 4, 2022

@langermank - I think I've to update macos to get to safari 15
regarding the box-shadow, I'm not sure what's the change you require. Should we have a box-shadow as a fallback on :focus?

@pksjce
Copy link
Collaborator Author

pksjce commented Apr 4, 2022

@colebemis - I'm not sure if the invisible button requires any special treatment. It is smaller in width because it doesn't have border of its own.

@langermank
Copy link
Contributor

regarding the box-shadow, I'm not sure what's the change you require. Should we have a box-shadow as a fallback on :focus?

The change makes the offset negative and changes the box-shadow to 3px instead of 2px:

outlineOffset: '-2'
boxShadow: 'inset 0 0 0 3px'

The box-shadow creates the solid white line between the primary button and the outline. I'm just setting it for :focus-visible and keeping the fallback simple (I'll confirm that later today).

@mperrotti
Copy link
Contributor

I am more confused about focus-visible in Safari. I can't seem to enable tabbing there

Safari is weird and you have to go to System Preferences > Keyboard > Shortcuts, and then check the "Use keyboard navigation..." at the bottom.

Screen Shot 2022-04-06 at 3 12 51 PM

there's no experimental feature and there is no pseudoclass for it in the developer tools.

@pksjce - you were right, you have to upgrade to Safari 15.4 to test :focus-visible. I have Safari 14, and I'm not getting any focus outlines. See this recording where I compare Primer CSS with Primer React keyboard navigation for buttons:
SafariOutlineInvisible

Check out how @langermank and team got consistent cross-browser behavior.

@pksjce
Copy link
Collaborator Author

pksjce commented Apr 7, 2022

Hey @mperrotti - It seems to be working fine on Safari now that I've updated it.

Screen.Recording.2022-04-07.at.2.35.16.pm.mov

@mperrotti
Copy link
Contributor

@pksjce - I still think we need to support Safari <15.4 like Primer CSS does. Do you want me to try to take that on since I still have 14 installed locally?

Copy link
Contributor

@mperrotti mperrotti left a comment

Choose a reason for hiding this comment

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

Tested in Safari 14, and it works the same as Primer CSS 🎉

@pksjce pksjce merged commit a8b3ed1 into main Apr 8, 2022
@pksjce pksjce deleted the pk/button-focus-styles branch April 8, 2022 08:15
@primer-css primer-css mentioned this pull request Apr 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants