@workday/canvas-kit-react
Version:
The parent module that contains all Workday Canvas Kit React components
17 lines (16 loc) • 667 B
JavaScript
import React from 'react';
import { createElemPropsHook } from '@workday/canvas-kit-react/common';
import { useComboboxModel } from './useComboboxModel';
/**
* Sets the width of the Menu to the target element when the menu is visible
*/
export const useSetPopupWidth = createElemPropsHook(useComboboxModel)(model => {
const visible = model.state.visibility !== 'hidden';
React.useLayoutEffect(() => {
var _a;
if (visible) {
model.events.setWidth(((_a = model.state.targetRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth) || 0);
}
}, [visible, model.events, model.state.targetRef]);
return {};
});