@workday/canvas-kit-react
Version:
The parent module that contains all Workday Canvas Kit React components
23 lines (22 loc) • 973 B
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSetPopupWidth = void 0;
const react_1 = __importDefault(require("react"));
const common_1 = require("@workday/canvas-kit-react/common");
const useComboboxModel_1 = require("./useComboboxModel");
/**
* Sets the width of the Menu to the target element when the menu is visible
*/
exports.useSetPopupWidth = (0, common_1.createElemPropsHook)(useComboboxModel_1.useComboboxModel)(model => {
const visible = model.state.visibility !== 'hidden';
react_1.default.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 {};
});
;