-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix(list): added #adapter.listItemAtIndexHasClass to prevent user state change to disabled items #4922
Conversation
…ion from changing the list item state
There are 2 different paths of selecting a listitem (w/ checkbox/radio/none) -
Pre-PR, MDC-List didn't allow any disabled checkboxes or radio buttons to be selected. |
Codecov Report
@@ Coverage Diff @@
## develop #4922 +/- ##
===========================================
- Coverage 98.67% 98.65% -0.02%
===========================================
Files 122 122
Lines 6032 6036 +4
Branches 796 797 +1
===========================================
+ Hits 5952 5955 +3
- Misses 79 80 +1
Partials 1 1
Continue to review full report at Codecov.
|
@@ -75,6 +75,12 @@ export interface MDCListAdapter { | |||
*/ | |||
isRootFocused(): boolean; | |||
|
|||
/** |
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.
You also need to sync this to internal and implement this adapter before merging 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.
@allan-chen LGTM! minor comment.
FOCUSABLE_CHILD_ELEMENTS: ` | ||
.${cssClasses.LIST_ITEM_CLASS} button:not(:disabled), | ||
.${cssClasses.LIST_ITEM_CLASS} a, | ||
.${cssClasses.LIST_ITEM_CLASS} input[type="radio"]:not(:disabled), | ||
.${cssClasses.LIST_ITEM_CLASS} input[type="checkbox"]:not(:disabled) | ||
`, | ||
RADIO_SELECTOR: 'input[type="radio"]:not(:disabled)', | ||
RADIO_SELECTOR: 'input[type="radio"]', |
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.
This began as an effort for better naming consistency but actually fixes a bug where if the first radio element of a list is disabled, the remaining radio list breaks. This was due to the following lines in layout()
of foundation.ts not realizing a disabled radio at index 0 also makes the whole list a radio list, as a result of the constant above.
...
else if (this.adapter_.hasRadioAtIndex(0)) {
this.isRadioList_ = true;
}
packages/mdc-list/constants.ts
Outdated
CHILD_ELEMENTS_TO_TOGGLE_TABINDEX: ` | ||
.${cssClasses.LIST_ITEM_CLASS} button:not(:disabled), | ||
.${cssClasses.LIST_ITEM_CLASS} a | ||
`, | ||
ENABLED_CHECKBOX_RADIO_SELECTOR: 'input[type="checkbox"]:not(:disabled), input[type="radio"]:not(:disabled)', | ||
ENABLED_CHECKBOX_SELECTOR: 'input[type="checkbox"]:not(:disabled)', |
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.
These two ENABLED_* constants are not used anywhere at this point. They are essentially renamed versions of the old CHECKBOX_RADIO_SELECTOR
and CHECKBOX_SELECTOR
before this PR, which were too restrictive in terms of what constituted a valid checkbox/radio to be toggled programmatically. Per Matt's philosophy that all programmatic changes to disabled checkboxes are allowed, I think we can remove these constants?
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.
We can remove if unused.
🤖 Beep boop! Screenshot test report 🚦6 screenshots changed from |
🤖 Beep boop! Screenshot test report 🚦6 screenshots changed from |
🤖 Beep boop! Screenshot test report 🚦6 screenshots changed from |
Make sure you add the breaking change notice to the merge request. |
fixes #4696
BREAKING CHANGE: New adapter method
listItemAtIndexHasClass