-
Notifications
You must be signed in to change notification settings - Fork 616
Add selected state to Button #1819
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -65,6 +65,20 @@ The `invisible` variant of `Button` indicates that the action is a low priority | |||||||||||||||||
</> | ||||||||||||||||||
``` | ||||||||||||||||||
|
||||||||||||||||||
### Selected button | ||||||||||||||||||
|
||||||||||||||||||
`Button` can be set to in a "selected" state in two ways. You can use a `selected` class or set `aria-selected ="true"`. | ||||||||||||||||||
This is in many cases similar to the active state of the button. Usually used in `ButtonGroup` when like tabs. | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this capability be restricted to
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 I don't understand what misuse of this pattern could look like. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We talked about this in the Primer React planning meeting. I don't think we want to restrict it to Kapture.2022-01-25.at.13.32.30.mp4There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think what we decided in the meeting is to utilize the @pksjce I may have missed this, but do you have the use case that prompted this ask to add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @langermank - this was the original issue where this came up #1783 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @rezrah.. that's an interesting use case 🤔 I still think this would be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are planning to deprecate the existing component as soon as possible. I think for parity we'd need to have it in the new one as well? The new component is not a refactor in terms of functionality I feel, only the API. Once you are done with primer/css#1874, we'd have to work on absorbing it into primer-react. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pksjce right, thanks for pointing that out. How do you see the new Button API changes rolling into PRC? In CSS and PVC, I think we'll likely end up creating a new component similar to how you've handled There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I'm not planning to have a |
||||||||||||||||||
|
||||||||||||||||||
```jsx live | ||||||||||||||||||
<> | ||||||||||||||||||
<drafts.Button aria-selected="true">Search</drafts.Button> | ||||||||||||||||||
<drafts.Button aria-selected="true" variant="danger"> | ||||||||||||||||||
Delete | ||||||||||||||||||
</drafts.Button> | ||||||||||||||||||
Comment on lines
+75
to
+78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to have examples for both ways of doing it :)
Suggested change
|
||||||||||||||||||
</> | ||||||||||||||||||
``` | ||||||||||||||||||
|
||||||||||||||||||
### Appending an icon | ||||||||||||||||||
|
||||||||||||||||||
We can place an inside the `Button` in either the leading or the trailing position to enhance the visual context. | ||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,11 @@ const Button = styled(ButtonBase)<ButtonBaseProps & SxProp>` | |
background-color: ${get('colors.btn.bg')}; | ||
border-color: ${get('colors.btn.border')}; | ||
} | ||
&.selected, | ||
&[aria-selected='true'] { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 good call on the |
||
background-color: ${get('colors.btn.selectedBg')}; | ||
box-shadow: ${get('colors.primer.shadow.inset')}; | ||
} | ||
|
||
${sx}; | ||
` | ||
|
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.
Is it worth adding a
selected
prop that handles both styling and setting aria attributes? May make consumer-side implementation easier. Also, I don't usually ask for users to set classes elsewhere to enable features, so could this be confusing?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.
Same! this was the exact confusion I was trying to discuss on slack as well. prop or class? Class is just not how we'd do this in react
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.
Should it be
aria-pressed
instead? 🤔cc @alliethu - what do you think the correct ARIA attribute might be?
Uh oh!
There was an error while loading. Please reload this page.
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.
Agreed that we should do it with a prop instead of a class or attribute selector.
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.
This came up today in the Primer patterns working session. We decided this should be purely visual and not set any ARIA attributes.
In the case where a button controls a dropdown, it would need to be passed
aria-haspopup
andaria-expanded
attributes. These attributes would be passed by the component that renders the dropdown button and menu.cc @langermank
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.
Two questions here
I'm thinking we need to implement
aria-pressed
styles and scrap theselected
prop.Uh oh!
There was an error while loading. Please reload this page.
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.
The two use cases here:
Sounds like Button state selected #1783 is using Button as a "toggle button", which isn't just a visual update but also a semantic change.
From MDN (https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-pressed):
It looks like it makes sense to add
aria-pressed
for toggle button. cc @alliethu for confirmationFor buttons that open a Menu,
aria-pressed
doens't make sense. Instead, we add the aria attributesaria-haspopup="true" aria-expanded="true"
, we can modify button styles if those are present OR to keep the two concerns independent, we can pass apressed
oractive
prop or className (not aria-pressed) to the Button from the Menu components.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.
Got it, so @mperrotti @siddharthkp I'm adding a
pressed
prop to the component and we can handle the css based on that. This will address both the above use cases.