-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Edit Post: Make sidebar header focusable for button focus normalization #21031
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 know we tried this before but forgot the conclusion, why don't we try to normalize it on the Button click handler (or related events).
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.
Asking cause it's not the first time we have the button click focus issues and certainly not the last time.
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've been thinking about this as well.
I think one of the main reluctances I'd have is in breaking expectations about how elements are expected to work, but I'm not sure how well this holds up:
On the technical front, I've been wondering as well just how this would work:
new window.Event
, how well does would it interoperate with React's event system, and in particular with portaled rendering which can't rely on DOM event bubbling?I've also been thinking about a few other options:
<input type="button">
susceptible to this as well? And if not, could we implement<Button>
this way? I expect by virtue of the differences between the two (largely ability to use non-text HTML content in<button>
), it may be infeasible.<span role="button">
? As I understand it, there are a lot of accessibility challenges in usingrole="button"
effectively, but if it were technically possible, we could absorb that complexity into the implementation of the core component.<button>
with<span tabindex="-1">
, essentially applying the behavior implemented here universally. There are some known issues here (huge proliferation of wrapping elements) and some unknown issues (potential side-effects of so many additional focusable elements).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 think @diegohaz might have good thoughts on this problem as something he probably already faced with reakit
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.
On Reakit we opted to ensure consistency across browsers on a
Tabbable
component (which is used byButton
): https://github.com/reakit/reakit/blob/c9f55d7d87f12b58ee409e8a392a9c36c2aadf52/packages/reakit/src/Tabbable/Tabbable.ts#L141-L148It's important to note that, on Firefox/macOS, calling
preventDefault()
there also prevents it to get the:active
state when clicked (ariakit/ariakit#432). Something likedata-active
could be used instead. That's the only bad side-effect people noticed so far.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.
@diegohaz Thanks for sharing! It hadn't occurred to me as potentially being as simple as calling
.focus()
on the button node. About the implementation and your point aboutpreventDefault
: Can you explain whypreventDefault
is necessary at all?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.
That's because Safari/Firefox on macOS will blur the button if it has focus on mouse down.
preventDefault
prevents that from happening. But there may be another way to work around that.