-
Notifications
You must be signed in to change notification settings - Fork 27
Expose "selectTab" method for programmatic selection #56
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
Conversation
Since the "selectTab" method is part of the class prototype, it is now exposed as the public API, enabling to programmatically select tabs.
src/index.ts
Outdated
* Out of bounds index | ||
*/ | ||
if (index > tabs.length - 1) { | ||
return |
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.
I think throwing a RangeError
here would be very useful.
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.
Looks great so far! Throwing would be helpful, and adding tests for out-of-bounds would be 😲 🎉
src/index.ts
Outdated
* Out of bounds index | ||
*/ | ||
if (index > tabs.length - 1) { | ||
throw new Error(`Cannot select tab at index "${index}" as it exceeds the total number of tabs`) |
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.
Perhaps a more succinct error message here:
throw new Error(`Cannot select tab at index "${index}" as it exceeds the total number of tabs`) | |
throw new RangeError(`Index "${index}" out of bounds`) |
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.
Sure :)
This looks fine to me. I've got slight worries that this might regress the experience for screenreader users, but I couldn't find anything about if we should announce when the tab changes to users. |
Not an accessibility expert at all. But, shouldn't setting My use case is to have a language switch on the website and once you select language (ie TypeScript or JavaScript), all the codeblocks on that page will switch to the selected language. tabs-switch.mov |
Any feedback guys? |
Thanks for your patience @thetutlage, this slipped between the cracks of our first responder rotation. @dgreif would you kindly give this some extra 👀 and if you're happy merge+release? |
Thanks :) |
This PR moves the
selectTab
method on theTabContainer
class. Doing so will enable programmatic select of tabs by calling this method. The proposal was shared in this issue #55Changes
selectTab
method no longer accepts thetabContainer
instance. It usesthis
implicitly.index > no of tabs
. Maybe we can raise an exception here? Just wanted feedback on how to proceed with that.Lemme know if something needs attention. Happy to improve the PR :)