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

Control the selectedTabIndex from the consuming application #1654

Closed
wants to merge 6 commits into from

Conversation

MiniHeyd
Copy link
Contributor

@MiniHeyd MiniHeyd commented Sep 21, 2023

πŸ“Œ 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 the did-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

  • Percy was checked for any visual regression
  • A11y tests have been run locally
  • A changelog entry was added via Changesets if needed

πŸ’¬ Please consider using conventional comments when reviewing this PR.

@vercel
Copy link

vercel bot commented Sep 21, 2023

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Updated (UTC)
hds-showcase βœ… Ready (Inspect) Visit Preview Sep 21, 2023 8:31pm
hds-website βœ… Ready (Inspect) Visit Preview Sep 21, 2023 8:31pm

// Set CSS custom properties for indicator
tabsParentElem.style.setProperty('--indicator-left-pos', tabLeftPos + 'px');
tabsParentElem.style.setProperty('--indicator-width', tabWidth + 'px');
next(() => {
Copy link
Contributor Author

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);
Copy link
Contributor Author

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();
Copy link
Contributor Author

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.

@MiniHeyd
Copy link
Contributor Author

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)
@didoo
Copy link
Contributor

didoo commented Oct 11, 2023

Implemented in #1688, so I am going to close this one. Thanks @MiniHeyd for spearheading the changes. πŸ™

@didoo didoo closed this Oct 11, 2023
@alex-ju alex-ju deleted the sheyd/selected-tab-condition branch October 11, 2023 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-website Content updates to the documentation website packages/components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants