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

Missing on:tabChanged event #23

Open
abiiranathan opened this issue Mar 2, 2022 · 5 comments
Open

Missing on:tabChanged event #23

abiiranathan opened this issue Mar 2, 2022 · 5 comments

Comments

@abiiranathan
Copy link

abiiranathan commented Mar 2, 2022

There is no way to restore the current state of the tabs. It would be nice to have an event fire when the tab changes. Users can update their svelte state and localStorage.

Something like...

<Tabs initialSelectedIndex={$tabIndex} on:tabChanged={index =>{
  tabIndex.set(index);
}>
	<TabList>
		<Tab>Triage</Tab>
	</TabList>

	<TabPanel>	
	     <TriageForm visit_id={visit.id} />	
	</TabPanel>

</Tabs>
@dojoVader
Copy link

Facing this current issue also

@dojoVader
Copy link

dojoVader commented Jul 12, 2022

I created a new file just to fix that

`<script>
import { getContext, onMount, tick, createEventDispatcher } from 'svelte';

import getId from 'svelte-tabs/src/id';
import { TABS } from 'svelte-tabs/src/Tabs.svelte';

let tabEl;

const tab = {
    id: getId()
};
const { registerTab, registerTabElement, selectTab, selectedTab, controls } = getContext(TABS);

let isSelected;
$: isSelected = $selectedTab === tab;

registerTab(tab);

const dispatcher = createEventDispatcher();

onMount(async () => {
    await tick();
    registerTabElement(tabEl);
});

function handleTabSelection(tab){
    selectTab(tab);
    dispatcher('changed',tab);
}
</script> <style> .svelte-tabs__tab { border: none; border-bottom: 2px solid transparent; color: #000000; cursor: pointer; list-style: none; display: inline-block; padding: 0.5em 0.75em; } .svelte-tabs__tab:focus { outline: thin dotted; } .svelte-tabs__selected { border-bottom: 2px solid #4F81E5; color: #4F81E5; } </style>
  • handleTabSelection(tab)}>
  • `

    @abiiranathan
    Copy link
    Author

    wow... I need to update. Thanks 👍👍👍

    @abiiranathan
    Copy link
    Author

    If all is well tested, submit a pull request to @nickyhajal

    @dojoVader
    Copy link

    I'll make a pull request.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants