Skip to content
This repository has been archived by the owner on Jan 20, 2022. It is now read-only.

Show focus on Button when interacting with keyboard #244

Merged
merged 5 commits into from
Oct 19, 2020

Conversation

justinanastos
Copy link
Contributor

@justinanastos justinanastos commented Oct 14, 2020

This uses @react-aria/focus under the hood to handle the focus. Also, this cleans up some internals of button.

Release Notes

  • Show focus ring around Button when keyboard focus is received
  • Use @react-aria/utils's mergeProps in Button
  • Add test to Button for className merging
📦 Published PR as canary version: 7.17.1-canary.244.5608.0

✨ Test out this PR locally via:

npm install @apollo/space-kit@7.17.1-canary.244.5608.0
# or 
yarn add @apollo/space-kit@7.17.1-canary.244.5608.0

@justinanastos justinanastos added the minor Increment the minor version when merged label Oct 14, 2020

mergedProps.onClick?.(event);
},
[mergedProps]
Copy link
Contributor

Choose a reason for hiding this comment

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

mergeProps is going to be a new object every render, so this useCallback can go away.
Or if wanted to keep it, probably need to store the merged props in a ref?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch 👍

[mergedProps]
);

const focusedStyles: ObjectInterpolation<any> = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this defaults to undefined inside the type, could we use that instead of any?

Suggested change
const focusedStyles: ObjectInterpolation<any> = {
const focusedStyles: ObjectInterpolation<undefined> = {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -447,7 +447,7 @@ In space constrained places or for floating action buttons (FAB), we can show an

### End Icons

You can specify that a button has an additional icon at the end of the row
You can specify that a button has an additional icon at the end of the row. This will be assumed to be a menu selector and will change the button's right padding.
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems a bit unexpected? I would expect icon and endIcon to behave similarly. If endIcon is for a specific use case maybe the name should reflect that.
Or remove endIcon and add a prop like isMenuSelect that changes the padding and moves the icon to the right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In retrospect I wish I'd named it something more like that; but this is already in place and now will just behave correctly 🤷‍♂️

This will _appear_ the same as before, but now the behavior is closer to
correct. Before when a user clicked, we would blur the button to not show
it's focused style. This was wrong for accessiblity because when a button
is clicked, it should retain the focus to allow tabbing. Now we use
`@react-aria/focus` to show the focus style if the user arrived on the
element with the keyboard only.
This does the things we're doing by hand automatically.
@justinanastos justinanastos merged commit 7664051 into main Oct 19, 2020
@justinanastos justinanastos deleted the justin/button-focus branch October 19, 2020 18:14
@apollo-bot2
Copy link
Collaborator

🚀 PR was released in v7.18.0 🚀

@apollo-bot2 apollo-bot2 added the released This issue/pull request has been released. label Oct 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
minor Increment the minor version when merged released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants