Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

fix(list): added #adapter.listItemAtIndexHasClass to prevent user state change to disabled items #4922

Merged
merged 10 commits into from
Sep 24, 2019

Conversation

moog16
Copy link
Contributor

@moog16 moog16 commented Jul 18, 2019

fixes #4696

BREAKING CHANGE: New adapter method listItemAtIndexHasClass

@moog16
Copy link
Contributor Author

moog16 commented Jul 18, 2019

There are 2 different paths of selecting a listitem (w/ checkbox/radio/none) - programatic and
via the user. This PR reflects the idea that

  1. all programatic changes should allow for the list item (w/ checkbox/radio) to be toggled
  2. all user interactions (click, keydown) should NOT allow list item (w/checkbox/radio) to be toggled.

Pre-PR, MDC-List didn't allow any disabled checkboxes or radio buttons to be selected.

@moog16 moog16 added this to the Sprint 7: July 9th - July 23rd milestone Jul 18, 2019
@codecov-io
Copy link

codecov-io commented Jul 18, 2019

Codecov Report

Merging #4922 into develop will decrease coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ
packages/mdc-list/component.ts 100% <100%> (ø) ⬆️
packages/mdc-list/foundation.ts 99.6% <100%> (ø) ⬆️
packages/mdc-dialog/foundation.ts 98.68% <0%> (-0.66%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bdf3430...7270720. Read the comment docs.

test/unit/mdc-list/mdc-list.test.js Outdated Show resolved Hide resolved
packages/mdc-list/foundation.ts Show resolved Hide resolved
packages/mdc-list/foundation.ts Outdated Show resolved Hide resolved
@@ -75,6 +75,12 @@ export interface MDCListAdapter {
*/
isRootFocused(): boolean;

/**
Copy link
Collaborator

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.

Copy link
Collaborator

@abhiomkar abhiomkar left a 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.

packages/mdc-list/constants.ts Outdated Show resolved Hide resolved
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"]',
Copy link
Collaborator

@allan-chen allan-chen Sep 19, 2019

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;
 }

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)',
Copy link
Collaborator

@allan-chen allan-chen Sep 19, 2019

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?

Copy link
Collaborator

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.

@mdc-web-bot
Copy link
Collaborator

@mdc-web-bot
Copy link
Collaborator

packages/mdc-list/adapter.ts Outdated Show resolved Hide resolved
@mdc-web-bot
Copy link
Collaborator

@patrickrodee
Copy link
Contributor

patrickrodee commented Sep 24, 2019

Make sure you add the breaking change notice to the merge request.

@allan-chen allan-chen changed the title fix(list): added #adapter.isListItemDisabled to prevent user interaction from changing the list item state fix(list): added #adapter.listItemAtIndexHasClass to prevent user state change to disabled items Sep 24, 2019
@allan-chen allan-chen merged commit b6d213c into develop Sep 24, 2019
@delete-merged-branch delete-merged-branch bot deleted the fix/list-checkbox-disabled branch September 24, 2019 18:31
@jamesmfriedman jamesmfriedman mentioned this pull request Nov 4, 2019
93 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants