({
collection,
containerRef,
...props
}: {collection: Collection<Node<unknown>>; containerRef: any} & TabsProps)
| 753 | }; |
| 754 | |
| 755 | let CollapsingTabs = ({ |
| 756 | collection, |
| 757 | containerRef, |
| 758 | ...props |
| 759 | }: {collection: Collection<Node<unknown>>; containerRef: any} & TabsProps) => { |
| 760 | let {orientation = 'horizontal', onSelectionChange} = props; |
| 761 | let [showItems, _setShowItems] = useState(true); |
| 762 | showItems = orientation === 'vertical' ? true : showItems; |
| 763 | let setShowItems = useCallback( |
| 764 | (value: boolean) => { |
| 765 | if (orientation === 'vertical') { |
| 766 | // if orientation is vertical, we always show the items |
| 767 | _setShowItems(true); |
| 768 | } else { |
| 769 | _setShowItems(value); |
| 770 | } |
| 771 | }, |
| 772 | [orientation] |
| 773 | ); |
| 774 | |
| 775 | let {direction} = useLocale(); |
| 776 | |
| 777 | let children = useMemo(() => [...collection], [collection]); |
| 778 | |
| 779 | let listRef = useRef<HTMLDivElement | null>(null); |
| 780 | |
| 781 | let updateOverflow = () => { |
| 782 | if (orientation === 'vertical' || !listRef.current || !containerRef?.current) { |
| 783 | return; |
| 784 | } |
| 785 | let container = listRef.current; |
| 786 | let containerRect = container.getBoundingClientRect(); |
| 787 | let tabs = container.querySelectorAll('[data-hidden-tab]'); |
| 788 | let lastTab = tabs[tabs.length - 1]; |
| 789 | let lastTabRect = lastTab.getBoundingClientRect(); |
| 790 | if (direction === 'ltr') { |
| 791 | setShowItems?.(lastTabRect.right <= containerRect.right); |
| 792 | } else { |
| 793 | setShowItems?.(lastTabRect.left >= containerRect.left); |
| 794 | } |
| 795 | }; |
| 796 | |
| 797 | let updateOverflowEffect = useEffectEvent(updateOverflow); |
| 798 | |
| 799 | useResizeObserver({ref: containerRef, onResize: updateOverflow}); |
| 800 | |
| 801 | useLayoutEffect(() => { |
| 802 | if (collection.size > 0) { |
| 803 | queueMicrotask(updateOverflowEffect); |
| 804 | } |
| 805 | }, [collection.size]); |
| 806 | |
| 807 | // start with null so that the first render won't have a flicker |
| 808 | let prevOrientation = useRef<Orientation | null>(null); |
| 809 | useLayoutEffect(() => { |
| 810 | if (collection.size > 0 && prevOrientation.current !== orientation) { |
| 811 | updateOverflowEffect(); |
| 812 | } |
nothing calls this directly
no test coverage detected