-
Notifications
You must be signed in to change notification settings - Fork 1k
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
fix: add trapFocus to RadioButtonGroup #7044
Draft
ShimiSun
wants to merge
1
commit into
master
Choose a base branch
from
fix/rbg-focus
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
import { Box, RadioButtonGroup } from 'grommet'; | ||
|
||
export const TrapFocus = () => { | ||
const [value, setValue] = useState({ value: '' }); | ||
|
||
const input = React.useRef(); | ||
|
||
useEffect(() => { | ||
setTimeout(() => { | ||
input.current?.focus(); | ||
console.log('here', input.current); | ||
}, 500); | ||
}, []); | ||
|
||
const postMethods = [ | ||
{ label: 'FTP', value: 'FTP' }, | ||
{ | ||
label: 'File System', | ||
value: 'FileSystem', | ||
}, | ||
{ | ||
label: 'FTP & File System', | ||
value: 'FTPCopy', | ||
}, | ||
]; | ||
|
||
// In this example there is no keyboard access to the RBG component | ||
// The trapFocus should fix the initial focus | ||
return ( | ||
<Box align="center" pad="large"> | ||
<RadioButtonGroup | ||
ref={input} | ||
name="radio" | ||
options={postMethods} | ||
value={value} | ||
onChange={(event) => setValue(event.value)} | ||
// trapFocus | ||
/> | ||
</Box> | ||
); | ||
}; | ||
export default { | ||
title: 'Input/RadioButtonGroup/Trap Focus', | ||
}; |
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.
Hey Shimi! Thanks for the proposal. I understand the use case, but I'm trying to think of a better way to handle it. A couple reactions:
trapFocus
as a prop name doesn't quite feel applicable here because in the case of Drop/Layer, trapFocus indicates that something should behave like a modal and not allow tab stops to continue to anywhere else on the page. That is a bit different from the intent here to place the focus on an individual radiobutton.setFocus
in the code is just a boolean to track if focus is set. I'm not following why we would set it to something other than a boolean here. Also, if I try to use arrows to navigate amongst the options in your storybook example, I can't. I would expect to be able to use keyboard to navigate.I don't have a suggestion at the moment for a better path, but just wanted to drop my reactions and let you know that I'm thinking on it.
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.
Thanks for the feedback @taysea, appreciate your time and thoughts on this.
I agree it is not trivial. I sent the initial proposal to get the convo started so I appreciate you chiming in.
Here are some follow-up thoughts.
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.
Thanks for working on this, I'm wondering if a potential workaround you team could use is before setting the focus on
input.current
check ifrole="radiogroup"
. If so instead of focusinginput.current
do something like this: