UNPKG

@workday/canvas-kit-react

Version:

The parent module that contains all Workday Canvas Kit React components

21 lines (20 loc) 1.04 kB
import { composeHooks, createElemPropsHook, useLocalRef, useMountLayout, } from '@workday/canvas-kit-react/common'; import { usePopupHeading, usePopupModel } from '@workday/canvas-kit-react/popup'; export const useModalHeading = composeHooks(usePopupHeading, createElemPropsHook(usePopupModel)((_, ref) => { const { elementRef, localRef } = useLocalRef(ref); useMountLayout(() => { var _a, _b, _c; if ((_c = (_b = (_a = localRef.current) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.querySelector('button')) === null || _c === void 0 ? void 0 : _c.textContent) { // First button is not a close icon button, set tabindex on the heading to capture initial focus localRef.current.setAttribute('tabindex', '0'); } }); const onBlur = () => { var _a; (_a = localRef.current) === null || _a === void 0 ? void 0 : _a.removeAttribute('tabindex'); }; return { ref: elementRef, onBlur, }; }));