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C,IAAI,qBAAqB,MAAM,UAAU,CAAC,IAAI,KAAK;IACnD,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,sBAAsB,MAAM,gBAAgB,CAAC,UAAU,KAAK,KAAK,GAAG,EACtE,MAAM,gBAAgB,CAAC,aAAa,CAAC;IAEzC,GAAG;QAAC;QAAoB,MAAM,gBAAgB;QAAE,KAAK,GAAG;KAAC;IAEzD,OAAO;QACL,mBAAmB;YACjB,GAAG,CAAA,GAAA,oCAAS,EACV,gBACA,eACA,YACA,kBACA,4DAA4D;YAC5D,qBAAqB;gBAAC,UAAU;YAAE,IAAI,KACvC;YACD,MAAM;YACN,IAAI,CAAA,GAAA,2CAAgB,EAAE,OAAO,KAAK,GAAG;YACrC,gBAAgB,KAAK,OAAO,IAAI,KAAK,OAAO,GAAG,IAAI,KAAK,OAAO,GAAG;YAClE,aAAa;QACf;mBACA;IACF;AACF","sources":["packages/react-aria/src/table/useTableColumnHeader.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 {DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';\nimport {getColumnHeaderId} from './utils';\nimport {GridNode} from 'react-stately/private/grid/GridCollection';\n// @ts-ignore\nimport intlMessages from '../../intl/table/*.json';\nimport {isAndroid} from '../utils/platform';\nimport {mergeProps} from '../utils/mergeProps';\nimport {TableState} from 'react-stately/useTableState';\nimport {useDescription} from '../utils/useDescription';\nimport {useEffect} from 'react';\nimport {useFocusable} from '../interactions/useFocusable';\nimport {useGridCell} from '../grid/useGridCell';\nimport {useLocalizedStringFormatter} from '../i18n/useLocalizedStringFormatter';\nimport {usePress} from '../interactions/usePress';\n\nexport interface AriaTableColumnHeaderProps<T> {\n  /** An object representing the [column header](https://www.w3.org/TR/wai-aria-1.1/#columnheader). Contains all the relevant information that makes up the column header. */\n  node: GridNode<T>,\n  /** Whether the [column header](https://www.w3.org/TR/wai-aria-1.1/#columnheader) is contained in a virtual scroller. */\n  isVirtualized?: boolean\n}\n\nexport interface TableColumnHeaderAria {\n  /** Props for the [column header](https://www.w3.org/TR/wai-aria-1.1/#columnheader) element. */\n  columnHeaderProps: DOMAttributes,\n  /** Whether the column is currently in a pressed state. */\n  isPressed: boolean\n}\n\n/**\n * Provides the behavior and accessibility implementation for a column header in a table.\n * @param props - Props for the column header.\n * @param state - State of the table, as returned by `useTableState`.\n * @param ref - The ref attached to the column header element.\n */\nexport function useTableColumnHeader<T>(props: AriaTableColumnHeaderProps<T>, state: TableState<T>, ref: RefObject<FocusableElement | null>): TableColumnHeaderAria {\n  let {node} = props;\n  let allowsSorting = node.props.allowsSorting;\n  // if there are no focusable children, the column header will focus the cell\n  let {gridCellProps} = useGridCell({...props, focusMode: 'child'}, state, ref);\n\n  let isSelectionCellDisabled = node.props.isSelectionCell && state.selectionManager.selectionMode === 'single';\n\n  let {pressProps, isPressed} = usePress({\n    isDisabled: !allowsSorting || isSelectionCellDisabled,\n    onPress() {\n      state.sort(node.key);\n    },\n    ref\n  });\n\n  // Needed to pick up the focusable context, enabling things like Tooltips for example\n  let {focusableProps} = useFocusable({}, ref);\n\n  let ariaSort: DOMAttributes['aria-sort'] | undefined = undefined;\n  let isSortedColumn = state.sortDescriptor?.column === node.key;\n  let sortDirection = state.sortDescriptor?.direction;\n  // aria-sort not supported in Android Talkback\n  if (node.props.allowsSorting && !isAndroid()) {\n    ariaSort = isSortedColumn ? sortDirection : 'none';\n  }\n\n  let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/table');\n  let sortDescription;\n  if (allowsSorting) {\n    sortDescription = `${stringFormatter.format('sortable')}`;\n    // Android Talkback doesn't support aria-sort so we add sort order details to the aria-described by here\n    if (isSortedColumn && sortDirection && isAndroid()) {\n      sortDescription = `${sortDescription}, ${stringFormatter.format(sortDirection)}`;\n    }\n  }\n\n  let descriptionProps = useDescription(sortDescription);\n\n  let shouldDisableFocus = state.collection.size === 0;\n  useEffect(() => {\n    if (shouldDisableFocus && state.selectionManager.focusedKey === node.key) {\n      state.selectionManager.setFocusedKey(null);\n    }\n  }, [shouldDisableFocus, state.selectionManager, node.key]);\n\n  return {\n    columnHeaderProps: {\n      ...mergeProps(\n        focusableProps,\n        gridCellProps,\n        pressProps,\n        descriptionProps,\n        // If the table is empty, make all column headers untabbable\n        shouldDisableFocus ? {tabIndex: -1} : null\n      ),\n      role: 'columnheader',\n      id: getColumnHeaderId(state, node.key),\n      'aria-colspan': node.colSpan && node.colSpan > 1 ? node.colSpan : undefined,\n      'aria-sort': ariaSort\n    },\n    isPressed\n  };\n}\n"],"names":[],"version":3,"file":"useTableColumnHeader.cjs.map"}