-
Notifications
You must be signed in to change notification settings - Fork 68
fix : handled checkbox and radio button check on press enter #957
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
Closed
speshkar-c-eightfold
wants to merge
13
commits into
EightfoldAI:main
from
speshkar-c-eightfold:speshkar/handleonenter-checkbox-radio
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
93f1c63
fix: on enter checkbox check
speshkar-c-eightfold 193328f
fix: radio button check on enter
speshkar-c-eightfold a6096a1
Merge branch 'main' into speshkar/handleonenter-checkbox-radio
speshkar-c-eightfold 2b810b3
Merge branch 'main' into speshkar/handleonenter-checkbox-radio
speshkar-c-eightfold e70326d
fix: added common handleKeydown functionality
speshkar-c-eightfold 4b87743
Merge branch 'main' into speshkar/handleonenter-checkbox-radio
speshkar-c-eightfold ef71473
Merge branch 'main' into speshkar/handleonenter-checkbox-radio
ypatadia-eightfold c133a9f
fix: removed any types
speshkar-c-eightfold 2918ece
fix: removed any types
speshkar-c-eightfold 98ea318
fix: fix checkbox issue on space added radio button condition
speshkar-c-eightfold 4b5289f
fix: console errors
speshkar-c-eightfold 72c8bcb
Merge branch 'main' into speshkar/handleonenter-checkbox-radio
ypatadia-eightfold 1cf7db9
Merge branch 'main' into speshkar/handleonenter-checkbox-radio
speshkar-c-eightfold 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -160,14 +160,37 @@ export const RadioButton: FC<RadioButtonProps> = React.forwardRef( | |
| setIsActive(radioGroupContext?.value === value); | ||
| }, [radioGroupContext?.value]); | ||
|
|
||
| const toggleChecked = (e: React.ChangeEvent<HTMLInputElement>): void => { | ||
| const applyRadioChange = ( | ||
| value: string, | ||
| e: React.SyntheticEvent<HTMLInputElement> | ||
| ) => { | ||
| if (!radioGroupContext) { | ||
| setSelectedValue(e.currentTarget?.value as RadioButtonValue); | ||
| setSelectedValue(value as RadioButtonValue); | ||
| } else { | ||
| radioGroupContext?.onChange?.(e); | ||
| radioGroupContext.onChange?.(e as React.ChangeEvent<HTMLInputElement>); | ||
| } | ||
|
|
||
| onChange?.(e); | ||
| onChange?.(e as React.ChangeEvent<HTMLInputElement>); | ||
| }; | ||
|
|
||
| const toggleChecked = (e: React.ChangeEvent<HTMLInputElement>): void => { | ||
| applyRadioChange(e.currentTarget.value, e); | ||
| }; | ||
|
|
||
| const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>): void => { | ||
| if (e.key === 'Enter' || e.key === ' ') { | ||
| const target = e.target as HTMLInputElement; | ||
|
|
||
| setIsActive((prev) => !prev); | ||
|
|
||
| const syntheticEvent = { | ||
| ...e, | ||
| currentTarget: target, | ||
| target: target, | ||
| } as unknown as React.ChangeEvent<HTMLInputElement>; | ||
|
|
||
| applyRadioChange(target.value, syntheticEvent); | ||
| } | ||
| }; | ||
|
Comment on lines
+163
to
194
Collaborator
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. |
||
|
|
||
| return ( | ||
|
|
@@ -196,6 +219,7 @@ export const RadioButton: FC<RadioButtonProps> = React.forwardRef( | |
| value={value} | ||
| onChange={!allowDisabledFocus ? toggleChecked : null} | ||
| readOnly | ||
| onKeyDown={!allowDisabledFocus ? handleKeyDown : null} | ||
| {...rest} | ||
speshkar-c-eightfold marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /> | ||
| <label htmlFor={radioButtonId.current} className={labelClassNames}> | ||
|
|
||
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.
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.
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.
can you please test these out. This implmentation for checkbox and radio ensures consistent implementation across both components.