Skip to content

Commit

Permalink
add initialSelectedIndex prop
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Attardi committed Aug 21, 2019
1 parent ce723fb commit a07286e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 34 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ A tabs component for Svelte
</Tabs>
```

## Props

- `initialSelectedIndex` (number): The index of the tab to initially select, when the Tabs component is mounted.

## Overriding styling

svelte-tabs comes with a basic default style, but it can be overridden. To override the styles to use your own, you will need to use global styles that have a higher specificity than the built-in styles.
Expand Down
43 changes: 12 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svelte-tabs",
"version": "1.0.1",
"version": "1.1.0",
"svelte": "src/index.js",
"module": "dist/index.mjs",
"main": "dist/index.js",
Expand Down
10 changes: 8 additions & 2 deletions src/Tabs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
</script>

<script>
import { afterUpdate, setContext, onDestroy, tick } from 'svelte';
import { afterUpdate, setContext, onDestroy, onMount, tick } from 'svelte';
import { writable } from 'svelte/store';
export let initialSelectedIndex = 0;
const tabElements = [];
const tabs = [];
const panels = [];
Expand Down Expand Up @@ -56,6 +58,10 @@
labeledBy
});
onMount(() => {
selectTab(tabs[initialSelectedIndex]);
});
afterUpdate(() => {
for (let i = 0; i < tabs.length; i++) {
controls.update(controlsData => ({...controlsData, [tabs[i].id]: panels[i].id}));
Expand Down Expand Up @@ -91,4 +97,4 @@

<div class="svelte-tabs" on:keydown={handleKeyDown}>
<slot></slot>
</div>
</div>

0 comments on commit a07286e

Please sign in to comment.