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

Fix dynamic tabs registration and a11y in NcAppSidebarTabs with provide/inject #3891

Merged
merged 3 commits into from Mar 28, 2023

Conversation

ShGKme
Copy link
Contributor

@ShGKme ShGKme commented Mar 15, 2023

Fixes: #3461

Currently, NcAppSidebarTabs gets content passed slot, goes throw all nodes, and detects NcAppSidebarTab instances. But it happened once on mounted and does not support tabs update.

In this solution:

  1. NcAppSidebarTabs provides:
    • registerTab method
    • unregisterTab method
    • activeTab property (replacement for $parent), could be reverted
  2. All NcAppSidebarTab register and unregister themself on created and beforeDestroy
  3. After registration NcAppSidebarTabs has the tab's data directly from the NcAppSidebarTabs

Sorting works the same way it was before. But there is no warnings if a user passes not-tabs as content.

This solution is fully compatible with Vue 3 as it is and Composition API.

1

2

Copy link
Contributor

@raimund-schluessler raimund-schluessler left a comment

Choose a reason for hiding this comment

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

I like the approach and I think that we can waive the warning when tabs and non-tabs are mixed. The keyboard navigation needs fixing, but that's an easy fix.

src/components/NcAppSidebar/NcAppSidebar.vue Show resolved Hide resolved
src/components/NcAppSidebar/NcAppSidebar.vue Show resolved Hide resolved
src/components/NcAppSidebar/NcAppSidebar.vue Outdated Show resolved Hide resolved
src/components/NcAppSidebar/NcAppSidebar.vue Outdated Show resolved Hide resolved
src/components/NcAppSidebar/NcAppSidebarTabs.vue Outdated Show resolved Hide resolved
src/components/NcAppSidebar/NcAppSidebarTabs.vue Outdated Show resolved Hide resolved
isActive() {
return this.$parent.activeTab === this.id
return this.activeTab === this.id
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

I just realized that this doesn't work in the Tasks app. I have no idea why, though.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ShGKme I think it would be a good idea to revert this change for now. We can still use it when we figure out why it's broken currently. For vue3 it works fine, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could be a problem with getter is old Vue is used. Updated with classic getter instead of computed.

@raimund-schluessler raimund-schluessler added bug Something isn't working enhancement New feature or request 3. to review Waiting for reviews feature: app-sidebar Related to the app-sidebar component labels Mar 15, 2023
@raimund-schluessler raimund-schluessler added this to the 7.8.1 milestone Mar 15, 2023
@raimund-schluessler
Copy link
Contributor

It currently does not work in the Tasks app, and I didn't figure out yet why.

@raimund-schluessler
Copy link
Contributor

It currently does not work in the Tasks app, and I didn't figure out yet why.

For some reason, the injected activeTab value is not reactive when I test it in the Tasks app. Reverting to return this.$parent.activeTab === this.id fixes this. But I have no idea why though, especially since it works in the netlify docs. 🤷

@julien-nc julien-nc modified the milestones: 7.8.1, 7.8.2 Mar 16, 2023
@raimund-schluessler
Copy link
Contributor

@ShGKme I pushed a few commits to fix some issues that I found, because I wanted to test the changes with my vue3 branch. If you don't like the changes, feel free to discard them.

@raimund-schluessler
Copy link
Contributor

I checked that the approach also works for vue3. A few adjustments are of course necessary, but it works fine for vue3 as well, see #3692.

@raimund-schluessler raimund-schluessler mentioned this pull request Mar 16, 2023
2 tasks
@mejo- mejo- modified the milestones: 7.8.2, 7.8.3 Mar 22, 2023
@nickvergessen nickvergessen modified the milestones: 7.8.3, 7.8.4, 7.8.5 Mar 23, 2023
@raimund-schluessler
Copy link
Contributor

@ShGKme Ping 🙂

@ShGKme
Copy link
Contributor Author

ShGKme commented Mar 27, 2023

@ShGKme Ping 🙂

Pong 👀. I'll work on this today.

@ShGKme ShGKme force-pushed the fix/3461/sidebar-tabs-provide-inject branch from 98ee351 to 92851bb Compare March 28, 2023 01:26
@ShGKme
Copy link
Contributor Author

ShGKme commented Mar 28, 2023

Rebased onto master and rewrote WIP commit

@ShGKme
Copy link
Contributor Author

ShGKme commented Mar 28, 2023

Finished fix

  • Removed mixing tabs and not tabs content test
  • Replace computed with classic getter in case that was the problem with the Tasks app
  • Fix activating tabs after registration/unregistration (active prop in prior)
  • NcAppSidebarTab's icon slot rendering method moved to NcAppSidebarTab as a public Tab's method
  • NcAppSidebarTab's icon slot default content rendering also moved to NcAppSidebarTab component (otherwise slot and default slot content were defined in a different components).
  • All exposed NcAppSidebarTab instance properties defined in expose

Fix a11y

  • Set active tab's tabindex to 0 instead of undefined. It allows to navigate to tabs with keyboard (Tab, SHIFT+Tab). Previously you could move from tab to tab's content but couldn't move back...
  • Handle Home and End keypress to navigate to the first/last tab according to w3

See: https://www.w3.org/TR/wai-aria-practices/examples/tabs/tabs-1/tabs.html

@raimund-schluessler Don't you know if previous behavior was intended? It wasn't possible to focus tabs navigation with Tab of Shift+Tab.

Tab

Updated docs with JSDocs for events and default slots and examples

DynamicTabs

Activating

CustomOrder

@ShGKme ShGKme changed the title DRAFT: Use provide/inject to register NcAppSidebarTab in NcAppSidebarTabs Fix dynamic tabs registration and a11y in NcAppSidebarTabs with provide/inject Mar 28, 2023
@ShGKme
Copy link
Contributor Author

ShGKme commented Mar 28, 2023

Tested in Talk

TabsTalk

@ShGKme ShGKme marked this pull request as ready for review March 28, 2023 02:11
Copy link
Contributor

@skjnldsv skjnldsv left a comment

Choose a reason for hiding this comment

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

Awesome work!

Copy link
Contributor

@raimund-schluessler raimund-schluessler left a comment

Choose a reason for hiding this comment

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

Works nicely now with Tasks as well!

@raimund-schluessler
Copy link
Contributor

Shall we squash the commits or merge as is?

ShGKme and others added 3 commits March 28, 2023 15:26
fix: #3461

Signed-off-by: Grigorii Shartsev <grigorii.shartsev@nextcloud.com>

Co-authored-by: Raimund Schlüßler <raimund.schluessler@mailbox.org>
Signed-off-by: Grigorii Shartsev <grigorii.shartsev@nextcloud.com>
Signed-off-by: Grigorii Shartsev <grigorii.shartsev@nextcloud.com>
@ShGKme
Copy link
Contributor Author

ShGKme commented Mar 28, 2023

Shall we squash the commits or merge as is?

I think, we may squash commits between the first WIP and finished fixing issue in fix dynamic tabs registration. But the last two other commits are less related to the original problem of the PR: a11y and general docs, I'd keep them separated.

I squashed with Co-authored-by, hope GH understands this :D

@ShGKme ShGKme force-pushed the fix/3461/sidebar-tabs-provide-inject branch from 871a53d to f1acfcc Compare March 28, 2023 13:35
@ShGKme ShGKme enabled auto-merge March 28, 2023 13:37
@skjnldsv skjnldsv added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Mar 28, 2023
@ShGKme ShGKme merged commit 490c4a1 into master Mar 28, 2023
15 checks passed
@ShGKme ShGKme deleted the fix/3461/sidebar-tabs-provide-inject branch March 28, 2023 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish bug Something isn't working enhancement New feature or request feature: app-sidebar Related to the app-sidebar component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[7.x] NcAppSidebarTabs prevents conditional NcAppSidebarTab
6 participants