|
41 | 41 | import type { TabScrollerComponentDev } from '@smui/tab-scroller'; |
42 | 42 | import TabScroller from '@smui/tab-scroller'; |
43 | 43 |
|
| 44 | + type PrimitiveKey = string | number; |
| 45 | + type TabKey = $$Generic<Object | PrimitiveKey>; |
| 46 | + interface $$Slots { |
| 47 | + default: { tab: TabKey }; |
| 48 | + } |
44 | 49 | const forwardEvents = forwardEventsBuilder(get_current_component()); |
45 | 50 |
|
46 | 51 | // Remember to update types file if you add/remove/rename props. |
47 | 52 | export let use: ActionArray = []; |
48 | 53 | let className = ''; |
49 | 54 | export { className as class }; |
50 | | - export let tabs: any[] = []; |
51 | | - export let key: (tab: any) => string | number = (tab) => tab; |
| 55 | + export let tabs: TabKey[] = []; |
| 56 | + export let key: (tab: TabKey) => PrimitiveKey = (tab) => tab as PrimitiveKey; |
52 | 57 | export let focusOnActivate = true; |
53 | 58 | export let focusOnProgrammatic = false; |
54 | 59 | export let useAutomaticActivation = true; |
55 | | - export let active: any | undefined = undefined; |
| 60 | + export let active: TabKey | undefined = undefined; |
56 | 61 |
|
57 | 62 | let element: HTMLDivElement; |
58 | 63 | let instance: MDCTabBarFoundation; |
59 | 64 | let tabScroller: TabScrollerComponentDev; |
60 | | - let activeIndex = tabs.indexOf(active); |
61 | | - let tabAccessorMap: { |
62 | | - [k: string]: SMUITabAccessor; |
63 | | - [k: number]: SMUITabAccessor; |
64 | | - } = {}; |
| 65 | + let activeIndex = tabs.indexOf(active!); |
| 66 | + let tabAccessorMap: Record<PrimitiveKey, SMUITabAccessor> = {}; |
65 | 67 | let tabAccessorWeakMap = new WeakMap<Object, SMUITabAccessor>(); |
66 | 68 | let skipFocus = false; |
67 | 69 |
|
68 | 70 | setContext('SMUI:tab:focusOnActivate', focusOnActivate); |
69 | 71 | setContext('SMUI:tab:initialActive', active); |
70 | 72 |
|
71 | 73 | $: if (active !== tabs[activeIndex]) { |
72 | | - activeIndex = tabs.indexOf(active); |
| 74 | + activeIndex = tabs.indexOf(active!); |
73 | 75 | if (instance) { |
74 | 76 | skipFocus = !focusOnProgrammatic; |
75 | 77 | instance.activateTab(activeIndex); |
|
82 | 84 | const accessor = |
83 | 85 | tabs[0] instanceof Object |
84 | 86 | ? tabAccessorWeakMap.get(tabs[0]) |
85 | | - : tabAccessorMap[tabs[0]]; |
| 87 | + : tabAccessorMap[tabs[0] as PrimitiveKey]; |
86 | 88 |
|
87 | 89 | if (accessor) { |
88 | 90 | accessor.forceAccessible(activeIndex === -1); |
|
134 | 136 | const activeElement = document.activeElement; |
135 | 137 | return tabElements.indexOf(activeElement as HTMLElement); |
136 | 138 | }, |
137 | | - getIndexOfTabById: (id) => tabs.indexOf(id), |
| 139 | + getIndexOfTabById: (id) => tabs.indexOf(id as TabKey), |
138 | 140 | getTabListLength: () => tabs.length, |
139 | 141 | notifyTabActivated: (index) => |
140 | 142 | dispatch( |
|
0 commit comments