|
1 | | -import React, { useLayoutEffect, useRef } from 'react'; |
| 1 | +import React, {useLayoutEffect, useRef} from 'react'; |
2 | 2 | import PropTypes from 'prop-types'; |
3 | 3 | export default function Popper(getDeps, props) { |
4 | | - const { createPopper, getPopperMaxHeight, getClassName, clk } = getDeps(); |
5 | | - const { TabsComponent, instance, hiddenTabIDs, btnRef } = props; |
| 4 | + const {createPopper, getPopperMaxHeight, getClassName, clk} = getDeps(); |
| 5 | + const {TabsComponent, instance, hiddenTabIDs, btnRef} = props; |
6 | 6 | const popperRef = useRef(); |
| 7 | + const ref = useRef(); |
| 8 | + ref.current = ref.current || {}; |
7 | 9 | useLayoutEffect(() => { |
8 | 10 | popperRef.current.style.maxHeight = getPopperMaxHeight(btnRef.current, 15) + 'px'; |
9 | 11 | const popperIns = createPopper(btnRef.current, popperRef.current); |
| 12 | + ref.current.popperIns = popperIns; |
10 | 13 | return () => { |
11 | 14 | popperIns.destroy(); |
12 | 15 | }; |
13 | 16 | }, []); |
14 | | - const { selectedTabID } = instance.getData(); |
| 17 | + useLayoutEffect(() => { |
| 18 | + ref.current.popperIns.update(); |
| 19 | + }, [hiddenTabIDs]); |
| 20 | + const {selectedTabID} = instance.getData(); |
15 | 21 | const openedTabIDs = hiddenTabIDs ? hiddenTabIDs.split(',') : []; |
16 | 22 | return ( |
17 | 23 | <> |
|
0 commit comments