-
Notifications
You must be signed in to change notification settings - Fork 77
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(radio-button): focuses first focusable radio-button element in group. #7152
Merged
anveshmekala
merged 11 commits into
master
from
anveshmekala/7113-fix-radio-button-first-focusable
Jun 21, 2023
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7e51b41
forceUpdate other radiobuttons in group
anveshmekala 1900ca3
Merge branch 'master' into anveshmekala/7113-fix-radio-button-first-f…
anveshmekala 1e2c62d
remove calcite-radio-group from tests
anveshmekala 4912760
feedback changes and add tests
anveshmekala 5356c56
Merge branch 'master' into anveshmekala/7113-fix-radio-button-first-f…
anveshmekala 4ac4434
Merge branch 'master' into anveshmekala/7113-fix-radio-button-first-f…
anveshmekala 9beb381
refactor
anveshmekala a943ebe
refactor e2e tests
anveshmekala 62ff46a
Merge branch 'master' into anveshmekala/7113-fix-radio-button-first-f…
anveshmekala 82dadee
remove console.log statements
anveshmekala 4926b92
fix typos and refactor if else with ternary
anveshmekala 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { | |
Element, | ||
Event, | ||
EventEmitter, | ||
forceUpdate, | ||
h, | ||
Host, | ||
Listen, | ||
|
@@ -179,9 +180,11 @@ export class RadioButton | |
) as HTMLCalciteRadioButtonElement[]; | ||
}; | ||
|
||
isDefaultSelectable = (): boolean => { | ||
isFocusable = (): boolean => { | ||
const radioButtons = this.queryButtons(); | ||
return !radioButtons.some((radioButton) => radioButton.checked) && radioButtons[0] === this.el; | ||
const firstFocusable = radioButtons.find((radiobutton) => !radiobutton.disabled); | ||
const checked = radioButtons.find((radiobutton) => radiobutton.checked); | ||
return firstFocusable === this.el && !checked; | ||
}; | ||
|
||
check = (): void => { | ||
|
@@ -271,11 +274,26 @@ export class RadioButton | |
}); | ||
} | ||
|
||
private updateTabIndexOfOtherRadioButtonsInGroup(): void { | ||
const radioButtons = this.queryButtons(); | ||
const otherFocusableRadioButtons = radioButtons.filter( | ||
(radioButton) => radioButton.guid !== this.guid && !radioButton.disabled | ||
); | ||
otherFocusableRadioButtons.forEach((radiobutton) => { | ||
forceUpdate(radiobutton); | ||
eriklharper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
} | ||
eriklharper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private getTabIndex(): number | undefined { | ||
if (this.disabled) { | ||
return undefined; | ||
} | ||
return this.checked || this.isDefaultSelectable() ? 0 : -1; | ||
if (this.checked || this.isFocusable()) { | ||
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. No love for the previous ternary? 😭 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. Oops, there was some extra code in |
||
this.updateTabIndexOfOtherRadioButtonsInGroup(); | ||
eriklharper marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return 0; | ||
} else { | ||
return -1; | ||
} | ||
} | ||
|
||
//-------------------------------------------------------------------------- | ||
|
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.
radiobutton
➡️radioButton