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
Control the selectedTabIndex from the consuming application #1654
Conversation
The latest updates on your projects. Learn more about Vercel for Git βοΈ
|
// Set CSS custom properties for indicator | ||
tabsParentElem.style.setProperty('--indicator-left-pos', tabLeftPos + 'px'); | ||
tabsParentElem.style.setProperty('--indicator-width', tabWidth + 'px'); | ||
next(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using next here allows for the nested tabs to properly set the indicator bar
@@ -69,7 +80,6 @@ export default class HdsTabsIndexComponent extends Component { | |||
@action | |||
onClick(tabIndex, event) { | |||
this.selectedTabIndex = tabIndex; | |||
this.setTabIndicator(tabIndex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This no longer needs to manually set since the component is watching for changes to this.selectedIndex
via the did-update
modifier and will fire this method when it changes.
|
||
schedule('afterRender', () => { | ||
this.setTabIndicator(initialTabIndex); | ||
this.setTabIndicator(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did-update
does not fire when the component is initially added so we need to fire this here to set the indicator on render.
Percy snapshot is good to go but I can not approve the build due to permissions |
β¦ this runs. This helps to ensure that during a route transition we wait until the new tabs are ready (the previous runloop will have ended)
π Summary
This PR will allow for the consuming application to manage the selected tab index state, in turn allowing for selected tab to be set after render by external controls.
π οΈ Detailed description
Currently the tab index is controlled by the
didInsert
method and can be initially set to any of the tabs through use of the@isSelected
tab arg. Subsequently the tab can only be changed by controls internal to the component, limiting more dynamic use cases like tracking selected tab as a query parameter and navigating with the browser back and forward buttons. This PR introduces the ability to pass in the selectedTabIndex as an arg on the parent component which will override the internal tracking of the selected tab index. This also moves the tab indicator logic to thedid-update
modifier, which is set up to fire when the selected index changes.Inspiration was taken from https://github.com/concordnow/ember-aria-tabs
πΈ Screenshots
Screen.Recording.2023-09-21.at.8.59.41.AM.mov
π External links
Jira ticket: HDS-XXX
Figma file: [if it applies]
π Component checklist
π¬ Please consider using conventional comments when reviewing this PR.