Comments (7)
You can also apply the active class to the appropriate tab nav and tab pane, just be sure to remove any existing classes.
It might make sense to use mutation observers to watch for the active
class on tab navs and then update the tab navs and tab panes automatically. I'll look into it, but I'd prefer to avoid turning this into an entire tab plugin.
from shoelace.
You can also apply the active class to the appropriate tab nav and tab pane, just be sure to remove any existing classes.
I tried that however I'm duplicating all of your code and I also need to fire the 'show' event. So I refactored my code and sent a click event to avoid that duplication.
I agree that using a mutation observer might be a cool way to handle this and removes the need for an explicit api.
from shoelace.
I tried that however I'm duplicating all of your code and I also need to fire the 'show' event. So I refactored my code and sent a click event to avoid that duplication.
Yeah, admittedly it's not as easy as it sounds since you have to traverse the DOM to remove other active classes.
I played with mutation observers a bit and they seem to work great for this. There are a couple edge cases I still need to work out (e.g. restricting disabled tabs from obtaining the active
class) but I think it's a good approach overall. Ultimately, you'd be able to just:
$('#tab-nav-id').addClass('active');
And everything else would happen automatically. This could be a great way to handle complex interactions in extensions too.
Let me play with it a bit more βΒ this is basically a completely rewrite of the tabs plugin. π
from shoelace.
This has been addressed in 7c2a0fc but it could use some testing (dist has been updated in master as well).
I'm using a mutation observer to detect class changes on tabs. When this occurs, other tabs are made inactive and the appropriate tab panes are shown/hidden automatically. Events still work as expected. Works for me even in IE11 which is the lowest target browser for scripts.
Tab docs have also been updated in the repo. Here's the relevant section:
To activate a tab programmatically, just add the
active
class to it. We use a mutation observer to remove the active class on other tabs and to show/hide the appropriate tab panes automatically.$('#tab-id').addClass('active');To disable a tab, add the
disabled
class to the appropriate tab.
Please try it out and report back.
from shoelace.
An interesting side effect of using mutation observers is that they let us prevent the active
class from being applied to a disabled tab. We basically block it and maintain the existing tab state. Good stuff.
from shoelace.
Looks good. Only tested on Chrome so far. Certainly a novel and nice way to do this.
from shoelace.
No reports of bugs, and it's testing out pretty solid for me. If any issues come up, please file as a bug :)
from shoelace.
Related Issues (20)
- Submenus in dropdown panels don't scroll HOT 1
- <sl-color-picker hoist> causes warning due to non-passive touchmove listener HOT 2
- sl-drawer issues when using keyboard navigation HOT 1
- Event bubbling doesn't appear to be working as described: event bubbles up then circles back around to the child element HOT 1
- events like sl-hide bubbling is confusing HOT 1
- page shake when dialog opend HOT 3
- sl-popup in scrollable section in<dialog> gets clipped in safari
- Dark theme not working, when installed via NPM HOT 1
- Form can still be implicitly submitted when primary button is a disabled shoelace component HOT 1
- sl-select: the small element used as an optgroup title should have its display set to block HOT 1
- Combining dropdown, menu and triggering a drawer causes a weird show animation HOT 4
- Component type resolution fails including Vue types HOT 4
- Translation mistake
- sl-range tooltip causes expensive layout recalc even when not visible
- `sl-divider` doesn't render in SvelteKit app using Autoloader HOT 3
- Button Group: Artifact in render in dropdown control HOT 4
- Select: incorrect size rendering in render in dropdown control HOT 1
- Form Controls: Error Messages: Firefox: Error Message Sticky on Page HOT 1
- Shoelace dark styles don't apply to :root, only :host
- Style parts of <sl-popup> within <sl-dropdown> (exportparts) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from shoelace.