diff --git a/components/_util/hooks/useRefs.ts b/components/_util/hooks/useRefs.ts new file mode 100644 index 000000000..965805e20 --- /dev/null +++ b/components/_util/hooks/useRefs.ts @@ -0,0 +1,20 @@ +import type { Ref, ComponentPublicInstance } from 'vue'; +import { onBeforeUpdate, ref } from 'vue'; +import type { Key } from '../type'; + +type RefType = HTMLElement | ComponentPublicInstance; +export type RefsValue = Map; +type UseRef = [(key: Key) => (el: RefType) => void, Ref]; +const useRefs = (): UseRef => { + const refs = ref(new Map()); + + const setRef = (key: Key) => (el: RefType) => { + refs.value.set(key, el); + }; + onBeforeUpdate(() => { + refs.value = new Map(); + }); + return [setRef, refs]; +}; + +export default useRefs; diff --git a/components/tabs/demo/centered.vue b/components/tabs/demo/centered.vue new file mode 100644 index 000000000..ffc58a171 --- /dev/null +++ b/components/tabs/demo/centered.vue @@ -0,0 +1,36 @@ + +--- +order: 2 +title: + zh-CN: 居中 + en-US: Centered +--- + +## zh-CN + +标签居中展示。 + +## en-US + +Centered tabs. + + + + + diff --git a/components/tabs/demo/custom-add-trigger.vue b/components/tabs/demo/custom-add-trigger.vue index a204d922c..de131cbf9 100644 --- a/components/tabs/demo/custom-add-trigger.vue +++ b/components/tabs/demo/custom-add-trigger.vue @@ -33,7 +33,7 @@ import { defineComponent, ref } from 'vue'; export default defineComponent({ setup() { - const panes = ref([ + const panes = ref<{ title: string; content: string; key: string; closable?: boolean }[]>([ { title: 'Tab 1', content: 'Content of Tab 1', key: '1' }, { title: 'Tab 2', content: 'Content of Tab 2', key: '2' }, ]); diff --git a/components/tabs/demo/custom-tab-bar.vue b/components/tabs/demo/custom-tab-bar.vue index c4a4cf637..3ed2fefb6 100644 --- a/components/tabs/demo/custom-tab-bar.vue +++ b/components/tabs/demo/custom-tab-bar.vue @@ -16,17 +16,13 @@ Customized bar of tab.