UNPKG

react-aria

Version:
1 lines 4.04 kB
{"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;;AA6CM,SAAS,0CACd,KAA4B,EAC5B,KAAsB,EACtB,GAAkC;IAElC,IAAI,eAAC,cAAc,kCAAc,qBAAqB,aAAY,GAAG;IACrE,IAAI,cAAC,UAAU,EAAE,kBAAkB,OAAO,gBAAE,YAAY,EAAC,GAAG;IAC5D,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,mCAAQ;IAC1B,IAAI,WAAW,CAAA,GAAA,oBAAM,EACnB,IAAM,IAAI,CAAA,GAAA,8CAAmB,EAAE,YAAY,WAAW,aAAa,eACnE;QAAC;QAAY;QAAc;QAAa;KAAU;IAGpD,IAAI,mBAAC,eAAe,EAAC,GAAG,CAAA,GAAA,iDAAsB,EAAE;aAC9C;QACA,kBAAkB;QAClB,kBAAkB;QAClB,eAAe,uBAAuB;QACtC,wBAAwB;QACxB,WAAW;QACX,cAAc;IAChB;IAEA,+BAA+B;IAC/B,IAAI,SAAS,CAAA,GAAA,+BAAI;IACjB,CAAA,GAAA,iCAAM,EAAE,GAAG,CAAC,OAAO;IAEnB,IAAI,oBAAoB,CAAA,GAAA,mCAAQ,EAAE;QAAC,GAAG,KAAK;QAAE,IAAI;IAAM;IAEvD,OAAO;QACL,cAAc;YACZ,GAAG,CAAA,GAAA,oCAAS,EAAE,iBAAiB,kBAAkB;YACjD,MAAM;YACN,oBAAoB;YACpB,UAAU;QACZ;IACF;AACF","sources":["packages/react-aria/src/tabs/useTabList.ts"],"sourcesContent":["/*\n * Copyright 2020 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 {\n AriaLabelingProps,\n DOMAttributes,\n DOMProps,\n Orientation,\n RefObject\n} from '@react-types/shared';\nimport {mergeProps} from '../utils/mergeProps';\nimport {TabListProps, TabListState} from 'react-stately/useTabListState';\nimport {tabsIds} from './utils';\nimport {TabsKeyboardDelegate} from './TabsKeyboardDelegate';\nimport {useId} from '../utils/useId';\nimport {useLabels} from '../utils/useLabels';\nimport {useLocale} from '../i18n/I18nProvider';\nimport {useMemo} from 'react';\nimport {useSelectableCollection} from '../selection/useSelectableCollection';\n\nexport interface AriaTabListProps<T> extends TabListProps<T>, DOMProps, AriaLabelingProps {\n /**\n * Whether tabs are activated automatically on focus or manually.\n *\n * @default 'automatic'\n */\n keyboardActivation?: 'automatic' | 'manual';\n /**\n * The orientation of the tabs.\n *\n * @default 'horizontal'\n */\n orientation?: Orientation;\n}\n\nexport interface AriaTabListOptions<T> extends Omit<AriaTabListProps<T>, 'children'> {}\n\nexport interface TabListAria {\n /** Props for the tablist container. */\n tabListProps: DOMAttributes;\n}\n\n/**\n * Provides the behavior and accessibility implementation for a tab list.\n * Tabs organize content into multiple sections and allow users to navigate between them.\n */\nexport function useTabList<T>(\n props: AriaTabListOptions<T>,\n state: TabListState<T>,\n ref: RefObject<HTMLElement | null>\n): TabListAria {\n let {orientation = 'horizontal', keyboardActivation = 'automatic'} = props;\n let {collection, selectionManager: manager, disabledKeys} = state;\n let {direction} = useLocale();\n let delegate = useMemo(\n () => new TabsKeyboardDelegate(collection, direction, orientation, disabledKeys),\n [collection, disabledKeys, orientation, direction]\n );\n\n let {collectionProps} = useSelectableCollection({\n ref,\n selectionManager: manager,\n keyboardDelegate: delegate,\n selectOnFocus: keyboardActivation === 'automatic',\n disallowEmptySelection: true,\n scrollRef: ref,\n linkBehavior: 'selection'\n });\n\n // Compute base id for all tabs\n let tabsId = useId();\n tabsIds.set(state, tabsId);\n\n let tabListLabelProps = useLabels({...props, id: tabsId});\n\n return {\n tabListProps: {\n ...mergeProps(collectionProps, tabListLabelProps),\n role: 'tablist',\n 'aria-orientation': orientation,\n tabIndex: undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"useTabList.cjs.map"}