import {tPopperHook} from "./createPopperHooks"; /** * 尺寸在对应方向上,限制popper与reference元素相等 * @author 韦胜健 * @date 2022/4/5 21:31 */ export function processSizeEqual({ hooks }: { hooks: tPopperHook }) { hooks.onStartRefresh.use(({ isVertical, refs, config }) => { if (!config.sizeEqual) {return;} if (isVertical) { refs.body.style.width = `${refs.reference.offsetWidth}px`; refs.content.style.width = '100%'; refs.content.style.overflowX = 'hidden'; } else { refs.body.style.height = `${refs.reference.offsetHeight}px`; refs.content.style.height = '100%'; refs.content.style.overflowY = 'hidden'; } }); hooks.onDestroy.use(({ isVertical, config, refs }) => { if (!config.sizeEqual) {return;} if (isVertical) { refs.body.style.width = ''; refs.content.style.width = ''; refs.content.style.overflowX = ''; } else { refs.body.style.height = ''; refs.content.style.height = ''; refs.content.style.overflowY = ''; } }); }