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: default tabindex property to undefined in TabIndexMixin #3627

Merged
merged 10 commits into from
Apr 6, 2022

Conversation

vursen
Copy link
Contributor

@vursen vursen commented Mar 31, 2022

Description

The PR refactors TabIndexMixin so that its tabindex property defaults to undefined rather than 0 which achieves fewer overrides in the components. There are only two cases at this moment when tabindex needs to be initialized as 0: it is vaadin-button and the legacy ShadowFocusMixin.

Type of change

  • Bugfix

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.

* @protected
*/
tabindex: {
type: Number,
value: 0,
Copy link
Contributor Author

@vursen vursen Mar 31, 2022

Choose a reason for hiding this comment

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

note: It would be better to have it null by default to entirely avoid undefined. However, that might be a breaking change for some components, so I decided not to change this behavior for now.

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.

Overall looks good. Let's update JSDoc annotation for the mixin as it still says:

By default, the attribute is set to 0 that makes the element focusable.

@vursen
Copy link
Contributor Author

vursen commented Apr 1, 2022

Overall looks good. Let's update JSDoc annotation for the mixin as it still says:

@web-padawan Thanks, updated.

* @protected
* @override
*/
_lastTabIndex: {
Copy link
Contributor Author

@vursen vursen Apr 1, 2022

Choose a reason for hiding this comment

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

note: It turned out that DelegateFocusMixin requires _lastTabIndex to be 0 by default even though the tabindex attribute is undefined by default.

If I remove it, the tests start failing. Seems that the __forwardTabIndex method is tied on the 0 value. It looks suspicious and it might be that a bug is hiding here, but I decided not to consider it in the scope of this refactoring.

@vursen vursen changed the title fix: restore tabindex attribute after re-enabling grid refactor: default tabindex property to undefined in TabIndexMixin Apr 1, 2022
@vursen vursen changed the title refactor: default tabindex property to undefined in TabIndexMixin refactor: default tabindex property to undefined in TabIndexMixin Apr 1, 2022
@vursen vursen force-pushed the fix/grid/restoring-tabindex-after-switching-disabled branch from ee345e6 to 0e1e9b7 Compare April 1, 2022 09:13
@vursen vursen changed the title refactor: default tabindex property to undefined in TabIndexMixin refactor: default tabindex property to undefined in TabIndexMixin Apr 1, 2022
super._disabledChanged(disabled, oldDisabled);

if (oldDisabled) {
this.removeAttribute('tabindex');
Copy link
Contributor Author

@vursen vursen Apr 1, 2022

Choose a reason for hiding this comment

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

note: The tabindex attribute is now removed by TabIndexMixin, which has become possible as a result of making _lastTabIndex default to undefined.

* @protected
*/
tabindex: {
value: 0
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this will affect the vaadin-select refactoring, which introduces a button mixin: https://github.com/vaadin/web-components/pull/3612/files#diff-936c1ce6ea70b0b86633d2f358c5c3cfa916ecfe6ad5376b5244ddbb04002315R18

If we want to apply tabindex=0 to the vaadin-select-value-button as well (which we do currently), we have to move this to the new button mixin. It looks like the snapshot tests for select should cover this, but just wanted to mention it regardless.

Copy link
Contributor Author

@vursen vursen Apr 1, 2022

Choose a reason for hiding this comment

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

It is a good reminder, thanks!

@vursen vursen force-pushed the fix/grid/restoring-tabindex-after-switching-disabled branch from 1900480 to c97ceae Compare April 4, 2022 07:49
@vursen vursen force-pushed the fix/grid/restoring-tabindex-after-switching-disabled branch 2 times, most recently from bfa0059 to 485bba1 Compare April 6, 2022 09:57
@vursen vursen force-pushed the fix/grid/restoring-tabindex-after-switching-disabled branch from 485bba1 to 0addf5b Compare April 6, 2022 12:33
@sonarqubecloud
Copy link

sonarqubecloud bot commented Apr 6, 2022

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 0 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 Vaadin 23.1.0.alpha2 and is also targeting the upcoming stable 23.1.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.

4 participants