Skip to content

Handle disabled focused tabs with tab JavaScript plugin#36169

Merged
mdo merged 15 commits intotwbs:mainfrom
julien-deramond:main-jd-disabled-tab-panes
May 6, 2022
Merged

Handle disabled focused tabs with tab JavaScript plugin#36169
mdo merged 15 commits intotwbs:mainfrom
julien-deramond:main-jd-disabled-tab-panes

Conversation

@julien-deramond
Copy link
Copy Markdown
Member

@julien-deramond julien-deramond commented Apr 14, 2022

Since 135b9cd, disabled tabs with tab JavaScript plugin don't seem to be handled anymore: they can be focused with the keyboard when disabled.
I've read the discussion in #33079 but I was unsure of the current state.

This PR tries to reintegrate this behavior (heavily draft atm) or at least shows the issue.

Note: with this current code, it doesn't work if the first tab is disabled and there are some issues when they are active + disabled.

If we use this PR to fix this use case

  • Add tests
  • Handle active + disabled
  • First tab is disabled
  • Only disabled tabs

Live preview

/cc @GeoSot

@julien-deramond julien-deramond force-pushed the main-jd-disabled-tab-panes branch from c34b612 to c1612f8 Compare April 14, 2022 05:50
@julien-deramond julien-deramond changed the title Handle disabled focused tabs with tab JavaScript plugin [WIP] Handle disabled focused tabs with tab JavaScript plugin Apr 14, 2022
Comment thread js/src/tab.js Outdated
Comment thread js/src/tab.js Outdated
Comment thread js/src/tab.js Outdated
@julien-deramond
Copy link
Copy Markdown
Member Author

julien-deramond commented Apr 19, 2022

Some tests were added via 437abdb.

Coverage before when launching only the Tab tests Statements : 32.53% ( 690/2121 )
Branches : 19.18% ( 199/1037 )
Functions : 21.28% ( 93/437 )
Lines : 32.94% ( 685/2079 )
New coverage when launching only the Tab tests Statements : 32.62% ( 691/2118 )
Branches : 19.47% ( 202/1037 )
Functions : 21.51% ( 94/437 )
Lines : 33.01% ( 685/2075 )

Proposal: Let's focus on this first fix for the 5.2.0 and try for a 5.2.1 or 5.3.0 to focus on the edge cases: active + disabled, first tab is disabled, only disabled tabs, etc. that I haven't tested yet in details. Please tell me your thoughts about this approach.

Note: You can retrieve 437abdb387dced04d2e8e12c124d6021cd5ac209 in local (just before 639333d) which contains a previous commit allowing you to play with a use case in the documentation.

@julien-deramond julien-deramond marked this pull request as ready for review April 19, 2022 16:57
@julien-deramond julien-deramond requested a review from a team as a code owner April 19, 2022 16:57
@julien-deramond julien-deramond changed the title [WIP] Handle disabled focused tabs with tab JavaScript plugin Handle disabled focused tabs with tab JavaScript plugin Apr 19, 2022
Comment thread js/tests/unit/tab.spec.js Outdated
@GeoSot
Copy link
Copy Markdown
Member

GeoSot commented Apr 19, 2022

Plus I liked the docs addon (removed by 639333d) 😢

@julien-deramond julien-deramond force-pushed the main-jd-disabled-tab-panes branch from 153ee5f to 233db35 Compare April 20, 2022 05:55
@julien-deramond
Copy link
Copy Markdown
Member Author

Plus I liked the docs addon (removed by 639333d) 😢

In order to have consistent examples in the documentation, in the same spirit, I've added in 3bdce71 a disabled tab for each example of the "JavaScript behavior" section as a last tab. Always using an example with .disabled and not the attribute.

@GeoSot
Copy link
Copy Markdown
Member

GeoSot commented Apr 20, 2022

In order to have consistent examples in the documentation, in the same spirit, I've added in 3bdce71 a disabled tab for each example of the "JavaScript behavior" section as a last tab. Always using an example with .disabled and not the attribute.

Yes, much much better. I want a favor though 👼
As a matter of fact, now, the disabled tabs can be placed in any order (except first), so some of them can change positions around the changed examples, can be. right?

Comment thread site/content/docs/5.1/components/navs-tabs.md Outdated
@julien-deramond
Copy link
Copy Markdown
Member Author

Yes, much much better. I want a favor though 👼 As a matter of fact, now, the disabled tabs can be placed in any order (except first), so some of them can change positions around the changed examples, can be. right?

I've changed the position for the vertical example in 3656437. I haven't changed the first 3 examples because IMHO they are working together to explain some concepts; I tried to change it and it seemed to me confusing to have a different tabs order while reading this part of the documentation. But if you still prefer a change of those 3 examples as well to shuffle those disabled tabs, no problem, I can do it.

Copy link
Copy Markdown
Member Author

@julien-deramond julien-deramond Apr 20, 2022

Choose a reason for hiding this comment

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

Probably to tackle in another issue but I'd say this button should only need the disabled attribute as in Buttons > Disabled state. I can't remove .disabled right now because the text becomes gray thanks to that class.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

probably css ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes. The current rule is:

&.disabled {
    color: var(--#{$prefix}nav-link-disabled-color);
    background-color: transparent;
    border-color: transparent;
}

We could add :disabled as a selector as well for example. But I'm waiting for Patrick's suggestion.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

+1 to using actual disabled attribute on <button>, but also allowing the same to happen with .disabled when author chose to use link or something

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for the feedback Patrick. Following the discussion in this comment, d613fa0 uses disabled attribute on <button> instead of .disabled. CSS rules have been added in _nav.scss to cover this use case.

@GeoSot
Copy link
Copy Markdown
Member

GeoSot commented Apr 20, 2022

/CC @patrickhlauke have you got any other suggestions here? 😄

@patrickhlauke
Copy link
Copy Markdown
Member

patrickhlauke commented Apr 23, 2022

Ok, looking purely at the example https://deploy-preview-36169--twbs-bootstrap.netlify.app/docs/5.1/components/navs-tabs/#javascript-behavior this looks decent and doing what it should. assuming that it handles it correctly if the disabled tab is the second-to-last or something, skipping it and setting focus to the one after it when you navigate through?

And yes I like the addition directly in the docs to have a disabled tab there in the example

@julien-deramond julien-deramond requested a review from a team as a code owner April 24, 2022 06:54
@julien-deramond
Copy link
Copy Markdown
Member Author

assuming that it handles it correctly if the disabled tab is the second-to-last or something, skipping it and setting focus to the one after it when you navigate through?

Yes it is. I chose to show it in the doc only for the vertical pills example to keep a certain consistency between all horizontal examples in the page. This is also covered in the unit tests.

@mdo
Copy link
Copy Markdown
Member

mdo commented Apr 26, 2022

@julien-deramond Let me know if/when this is good to merge for you :)

@julien-deramond
Copy link
Copy Markdown
Member Author

@julien-deramond Let me know if/when this is good to merge for you :)

This is good to merge. I'll track the remaining edge cases in an issue for the next 5.2.x version.

@mdo mdo force-pushed the main-jd-disabled-tab-panes branch from d613fa0 to abfff09 Compare April 26, 2022 17:48
Comment thread scss/_nav.scss Outdated
@mdo mdo force-pushed the main-jd-disabled-tab-panes branch from abfff09 to 3b8ce95 Compare May 6, 2022 00:11
@mdo mdo force-pushed the main-jd-disabled-tab-panes branch from 3b8ce95 to 8501ec7 Compare May 6, 2022 02:16
@mdo mdo merged commit 5d9500b into twbs:main May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

No open projects
Status: Todo

Development

Successfully merging this pull request may close these issues.

5 participants