react-aria
Version:
Spectrum UI components in React
1 lines • 2.65 kB
Source Map (JSON)
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AAMM,SAAS,0CACd,eAA0C,IAAI;IAE9C,0FAA0F;IAC1F,oIAAoI;IACpI,IAAI,CAAC,SAAS,WAAW,GAAG,CAAA,GAAA,qBAAO,EAAE;IACrC,IAAI,SAAS,CAAA,GAAA,mBAAK,EAAE;IAEpB,iEAAiE;IACjE,uDAAuD;IACvD,IAAI,MAAM,CAAA,GAAA,wBAAU,EAAE,CAAC;QACrB,OAAO,OAAO,GAAG;QACjB,WAAW,CAAC,CAAC;IACf,GAAG,EAAE;IAEL,2DAA2D;IAC3D,CAAA,GAAA,yCAAc,EAAE;QACd,IAAI,CAAC,OAAO,OAAO,EACjB,WAAW;IAEf,GAAG,EAAE;IAEL,OAAO;QAAC;QAAK;KAAQ;AACvB;AAOO,SAAS,0CAAW,eAA0C,IAAI;IACvE,IAAI,KAAK,CAAA,GAAA,+BAAI;IACb,IAAI,CAAC,KAAK,QAAQ,GAAG,0CAAQ;IAE7B,OAAO;QACL,IAAI,UAAU,KAAK;aACnB;IACF;AACF","sources":["packages/react-aria/src/utils/useSlot.ts"],"sourcesContent":["/*\n * Copyright 2026 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {RefCallback, useCallback, useRef, useState} from 'react';\nimport {useId} from './useId';\nimport {useLayoutEffect} from './useLayoutEffect';\n\nexport function useSlot(\n initialState: boolean | (() => boolean) = true\n): [RefCallback<any>, boolean] {\n // Initial state is typically based on the parent having an aria-label or aria-labelledby.\n // If it does, this value should be false so that we don't update the state and cause a rerender when we go through the layoutEffect\n let [hasSlot, setHasSlot] = useState(initialState);\n let hasRun = useRef(false);\n\n // A callback ref which will run when the slotted element mounts.\n // This should happen before the useLayoutEffect below.\n let ref = useCallback((el: any) => {\n hasRun.current = true;\n setHasSlot(!!el);\n }, []);\n\n // If the callback hasn't been called, then reset to false.\n useLayoutEffect(() => {\n if (!hasRun.current) {\n setHasSlot(false);\n }\n }, []);\n\n return [ref, hasSlot];\n}\n\ninterface SlotAria {\n id: string | undefined;\n ref: RefCallback<any>;\n}\n\nexport function useSlotId2(initialState: boolean | (() => boolean) = true): SlotAria {\n let id = useId();\n let [ref, hasSlot] = useSlot(initialState);\n\n return {\n id: hasSlot ? id : undefined,\n ref\n };\n}\n"],"names":[],"version":3,"file":"useSlot.cjs.map"}