Skip to content
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

refactor!: update checkbox to use slotted input #2539

Merged
merged 32 commits into from
Sep 21, 2021
Merged

Conversation

vursen
Copy link
Contributor

@vursen vursen commented Sep 15, 2021

Description

The PR re-implements <vaadin-checkbox> to make it use slotted input. Using slotted input improves the checkbox's accessibility as proven by the prototype.

Along the way, the PR introduces the label attribute for the checkbox. The attribute can be used as an alternative way to define a label for a checkbox besides using the default slot.

  • Re-implement <vaadin-checkbox> to use the slotted input.
  • Adapt the Lumo theme and corresponding visual tests to the slotted input.
  • Adapt the Material theme and corresponding visual tests to the slotted input.
  • Make unit tests of <vaadin-checkbox> pass.
  • Make unit tests of <vaadin-checkbox-group> pass.
  • Make unit tests of <vaadin-grid-pro> pass (see the comment).

Fixes #2212
Fixes #980

Type of change

  • Breaking change

Checklist

  • I have read the contribution guide: https://vaadin.com/docs-beta/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

@vursen vursen changed the title feat!: re-implement checkbox with new mixins and slotted input (WIP) feat!: re-implement checkbox with slotted input and new mixins (WIP) Sep 15, 2021
@vursen vursen changed the title feat!: re-implement checkbox with slotted input and new mixins (WIP) feat!: re-implement checkbox using slotted input and new mixins (WIP) Sep 15, 2021
@vursen vursen changed the title feat!: re-implement checkbox using slotted input and new mixins (WIP) refactor!: update checkbox to use slotted input (WIP) Sep 16, 2021
@vursen vursen force-pushed the feat/checkbox branch 4 times, most recently from b8e1833 to d82402e Compare September 17, 2021 09:27
Comment on lines -40 to -42
this.addEventListener('blur', () => {
this._setActive(false);
});
Copy link
Contributor Author

@vursen vursen Sep 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: Having this blur listener causes the checkbox to lose the active attribute in case the user switches the checkbox by clicking on the label (for some reason, there is fired the blur event on <vaadin-checkbox> (!!) while moving focus between the input and the label).

Didn't have enough time to investigate that all the way but I assume the blur listener can be removed altogether.
It originally came to the mixin from the button component. However, even for the button, it doesn't look relevant since we changed its implementation so that there are not any native buttons.

});

it('empty', async () => {
element.label = '';
Copy link
Contributor Author

@vursen vursen Sep 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: The margin between the label and the input is defined separately for the RTL and LTL modes. The margin should disappear when there is no label. That being so, I thought it is reasonable to test the empty label case for both modes.

@vursen
Copy link
Contributor Author

vursen commented Sep 17, 2021

Some of the visual tests are failing now due to an issue that is not actually caused by this PR:

packages/custom-field/test/visual/lumo/custom-field.test.js:

 ❌ custom-field > alignment > label + helper text > label + helper text alignment
      Error: Visual diff failed. New screenshot is 0.01% different.
      See diff for details: /Users/vursen/dev/vaadin/web-components/packages/custom-field/test/visual/lumo/screenshots/custom-field/failed/alignment-label-helper-text-diff.png
        at async o.<anonymous> (packages/custom-field/test/visual/lumo/custom-field.test.js:185:9)

Failing tests are going to be fixed in #2532. Fixed.

@vursen vursen changed the title refactor!: update checkbox to use slotted input (WIP) refactor!: update checkbox to use slotted input Sep 17, 2021
@vursen
Copy link
Contributor Author

vursen commented Sep 20, 2021

One of the <vaadin-grid-pro> unit tests is still failing because the click event fired on the checkbox gets prevented here:

 ❌ edit column editor type > checkbox > should update value from checkbox checked after edit mode exit
      AssertionError: expected 'true' to equal 'false'
      + expected - actual
      
      -true
      +false
      
      at r (node_modules/@esm-bundle/chai/node_modules/.pnpm/[email protected]/node_modules/chai/chai.js:9576:21)
      at node_modules/@esm-bundle/chai/node_modules/.pnpm/[email protected]/node_modules/chai/chai.js:251:8
      at p (node_modules/@esm-bundle/chai/node_modules/.pnpm/[email protected]/node_modules/chai/chai.js:1410:10)
      at c (node_modules/@esm-bundle/chai/node_modules/.pnpm/[email protected]/node_modules/chai/chai.js:7884:30)
      at handleDom (node_modules/@open-wc/semantic-dom-diff/chai-dom-diff.js:102:21)
      at f (node_modules/@esm-bundle/chai/node_modules/.pnpm/[email protected]/node_modules/chai/chai.js:9164:38)
      at packages/vaadin-grid-pro/test/edit-column-type.test.js:113:56

... and I'm currently searching for a way to fix it.

@vursen vursen marked this pull request as ready for review September 20, 2021 09:30
packages/checkbox-group/test/checkbox-group.test.js Outdated Show resolved Hide resolved
packages/checkbox/src/vaadin-checkbox.d.ts Outdated Show resolved Hide resolved
packages/checkbox/test/checkbox.test.js Outdated Show resolved Hide resolved
Copy link
Member

@web-padawan web-padawan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @vursen for your attention to detail 💯

@sonarcloud
Copy link

sonarcloud bot commented Sep 21, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 6 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with platform 22.0.0.alpha7 and is also targeting the upcoming stable 22.0.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Re-implement checkbox using slotted input and new mixins [checkbox] Should we introduce the label property?
4 participants