{"version":3,"file":"FocusTrap.cjs","names":["getSingleElementChild","VisuallyHidden"],"sources":["../../../src/components/FocusTrap/FocusTrap.tsx"],"sourcesContent":["import { cloneElement } from 'react';\nimport { useFocusTrap, useMergedRef } from '@mantine/hooks';\nimport { getSingleElementChild } from '../../core';\nimport { VisuallyHidden } from '../VisuallyHidden';\n\nexport interface FocusTrapProps {\n  /** Element to trap focus at, must support ref prop */\n  children: any;\n\n  /** If set to `false`, disables focus trap */\n  active?: boolean;\n\n  /** Prop that is used to access element ref @default 'ref' */\n  refProp?: string;\n\n  /** Ref to combine with the focus trap ref */\n  innerRef?: React.Ref<any>;\n}\n\nexport function FocusTrap({\n  children,\n  active = true,\n  refProp = 'ref',\n  innerRef,\n}: FocusTrapProps): React.ReactElement {\n  const focusTrapRef = useFocusTrap(active);\n  const ref = useMergedRef(focusTrapRef, innerRef);\n\n  const child = getSingleElementChild(children);\n  if (!child) {\n    return children;\n  }\n\n  return cloneElement(child, { [refProp]: ref });\n}\n\nexport function FocusTrapInitialFocus(props: React.ComponentProps<'span'>) {\n  return <VisuallyHidden tabIndex={-1} data-autofocus {...props} />;\n}\n\nFocusTrap.displayName = '@mantine/core/FocusTrap';\nFocusTrapInitialFocus.displayName = '@mantine/core/FocusTrapInitialFocus';\nFocusTrap.InitialFocus = FocusTrapInitialFocus;\n\nexport namespace FocusTrap {\n  export type Props = FocusTrapProps;\n}\n"],"mappings":";;;;;;;;AAmBA,SAAgB,UAAU,EACxB,UACA,SAAS,MACT,UAAU,OACV,YACqC;CAErC,MAAM,OAAA,GAAA,eAAA,eAAA,GAAA,eAAA,cAD4B,OAAO,EACF,SAAS;CAEhD,MAAM,QAAQA,iCAAAA,sBAAsB,SAAS;AAC7C,KAAI,CAAC,MACH,QAAO;AAGT,SAAA,GAAA,MAAA,cAAoB,OAAO,GAAG,UAAU,KAAK,CAAC;;AAGhD,SAAgB,sBAAsB,OAAqC;AACzE,QAAO,iBAAA,GAAA,kBAAA,KAACC,uBAAAA,gBAAD;EAAgB,UAAU;EAAI,kBAAA;EAAe,GAAI;EAAS,CAAA;;AAGnE,UAAU,cAAc;AACxB,sBAAsB,cAAc;AACpC,UAAU,eAAe"}