@react-aria/tag 3.8.0 → 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/import.mjs +2 -4
- package/dist/main.js +3 -5
- package/dist/main.js.map +1 -1
- package/dist/module.js +2 -4
- package/dist/module.js.map +1 -1
- package/dist/types/src/index.d.ts +2 -0
- package/package.json +15 -20
- package/src/index.ts +2 -4
- package/dist/ar-AE.main.js +0 -7
- package/dist/ar-AE.main.js.map +0 -1
- package/dist/ar-AE.mjs +0 -9
- package/dist/ar-AE.module.js +0 -9
- package/dist/ar-AE.module.js.map +0 -1
- package/dist/bg-BG.main.js +0 -7
- package/dist/bg-BG.main.js.map +0 -1
- package/dist/bg-BG.mjs +0 -9
- package/dist/bg-BG.module.js +0 -9
- package/dist/bg-BG.module.js.map +0 -1
- package/dist/cs-CZ.main.js +0 -7
- package/dist/cs-CZ.main.js.map +0 -1
- package/dist/cs-CZ.mjs +0 -9
- package/dist/cs-CZ.module.js +0 -9
- package/dist/cs-CZ.module.js.map +0 -1
- package/dist/da-DK.main.js +0 -7
- package/dist/da-DK.main.js.map +0 -1
- package/dist/da-DK.mjs +0 -9
- package/dist/da-DK.module.js +0 -9
- package/dist/da-DK.module.js.map +0 -1
- package/dist/de-DE.main.js +0 -7
- package/dist/de-DE.main.js.map +0 -1
- package/dist/de-DE.mjs +0 -9
- package/dist/de-DE.module.js +0 -9
- package/dist/de-DE.module.js.map +0 -1
- package/dist/el-GR.main.js +0 -7
- package/dist/el-GR.main.js.map +0 -1
- package/dist/el-GR.mjs +0 -9
- package/dist/el-GR.module.js +0 -9
- package/dist/el-GR.module.js.map +0 -1
- package/dist/en-US.main.js +0 -7
- package/dist/en-US.main.js.map +0 -1
- package/dist/en-US.mjs +0 -9
- package/dist/en-US.module.js +0 -9
- package/dist/en-US.module.js.map +0 -1
- package/dist/es-ES.main.js +0 -7
- package/dist/es-ES.main.js.map +0 -1
- package/dist/es-ES.mjs +0 -9
- package/dist/es-ES.module.js +0 -9
- package/dist/es-ES.module.js.map +0 -1
- package/dist/et-EE.main.js +0 -7
- package/dist/et-EE.main.js.map +0 -1
- package/dist/et-EE.mjs +0 -9
- package/dist/et-EE.module.js +0 -9
- package/dist/et-EE.module.js.map +0 -1
- package/dist/fi-FI.main.js +0 -7
- package/dist/fi-FI.main.js.map +0 -1
- package/dist/fi-FI.mjs +0 -9
- package/dist/fi-FI.module.js +0 -9
- package/dist/fi-FI.module.js.map +0 -1
- package/dist/fr-FR.main.js +0 -7
- package/dist/fr-FR.main.js.map +0 -1
- package/dist/fr-FR.mjs +0 -9
- package/dist/fr-FR.module.js +0 -9
- package/dist/fr-FR.module.js.map +0 -1
- package/dist/he-IL.main.js +0 -7
- package/dist/he-IL.main.js.map +0 -1
- package/dist/he-IL.mjs +0 -9
- package/dist/he-IL.module.js +0 -9
- package/dist/he-IL.module.js.map +0 -1
- package/dist/hr-HR.main.js +0 -7
- package/dist/hr-HR.main.js.map +0 -1
- package/dist/hr-HR.mjs +0 -9
- package/dist/hr-HR.module.js +0 -9
- package/dist/hr-HR.module.js.map +0 -1
- package/dist/hu-HU.main.js +0 -7
- package/dist/hu-HU.main.js.map +0 -1
- package/dist/hu-HU.mjs +0 -9
- package/dist/hu-HU.module.js +0 -9
- package/dist/hu-HU.module.js.map +0 -1
- package/dist/intlStrings.main.js +0 -108
- package/dist/intlStrings.main.js.map +0 -1
- package/dist/intlStrings.mjs +0 -110
- package/dist/intlStrings.module.js +0 -110
- package/dist/intlStrings.module.js.map +0 -1
- package/dist/it-IT.main.js +0 -7
- package/dist/it-IT.main.js.map +0 -1
- package/dist/it-IT.mjs +0 -9
- package/dist/it-IT.module.js +0 -9
- package/dist/it-IT.module.js.map +0 -1
- package/dist/ja-JP.main.js +0 -7
- package/dist/ja-JP.main.js.map +0 -1
- package/dist/ja-JP.mjs +0 -9
- package/dist/ja-JP.module.js +0 -9
- package/dist/ja-JP.module.js.map +0 -1
- package/dist/ko-KR.main.js +0 -7
- package/dist/ko-KR.main.js.map +0 -1
- package/dist/ko-KR.mjs +0 -9
- package/dist/ko-KR.module.js +0 -9
- package/dist/ko-KR.module.js.map +0 -1
- package/dist/lt-LT.main.js +0 -7
- package/dist/lt-LT.main.js.map +0 -1
- package/dist/lt-LT.mjs +0 -9
- package/dist/lt-LT.module.js +0 -9
- package/dist/lt-LT.module.js.map +0 -1
- package/dist/lv-LV.main.js +0 -7
- package/dist/lv-LV.main.js.map +0 -1
- package/dist/lv-LV.mjs +0 -9
- package/dist/lv-LV.module.js +0 -9
- package/dist/lv-LV.module.js.map +0 -1
- package/dist/nb-NO.main.js +0 -7
- package/dist/nb-NO.main.js.map +0 -1
- package/dist/nb-NO.mjs +0 -9
- package/dist/nb-NO.module.js +0 -9
- package/dist/nb-NO.module.js.map +0 -1
- package/dist/nl-NL.main.js +0 -7
- package/dist/nl-NL.main.js.map +0 -1
- package/dist/nl-NL.mjs +0 -9
- package/dist/nl-NL.module.js +0 -9
- package/dist/nl-NL.module.js.map +0 -1
- package/dist/pl-PL.main.js +0 -7
- package/dist/pl-PL.main.js.map +0 -1
- package/dist/pl-PL.mjs +0 -9
- package/dist/pl-PL.module.js +0 -9
- package/dist/pl-PL.module.js.map +0 -1
- package/dist/pt-BR.main.js +0 -7
- package/dist/pt-BR.main.js.map +0 -1
- package/dist/pt-BR.mjs +0 -9
- package/dist/pt-BR.module.js +0 -9
- package/dist/pt-BR.module.js.map +0 -1
- package/dist/pt-PT.main.js +0 -7
- package/dist/pt-PT.main.js.map +0 -1
- package/dist/pt-PT.mjs +0 -9
- package/dist/pt-PT.module.js +0 -9
- package/dist/pt-PT.module.js.map +0 -1
- package/dist/ro-RO.main.js +0 -7
- package/dist/ro-RO.main.js.map +0 -1
- package/dist/ro-RO.mjs +0 -9
- package/dist/ro-RO.module.js +0 -9
- package/dist/ro-RO.module.js.map +0 -1
- package/dist/ru-RU.main.js +0 -7
- package/dist/ru-RU.main.js.map +0 -1
- package/dist/ru-RU.mjs +0 -9
- package/dist/ru-RU.module.js +0 -9
- package/dist/ru-RU.module.js.map +0 -1
- package/dist/sk-SK.main.js +0 -7
- package/dist/sk-SK.main.js.map +0 -1
- package/dist/sk-SK.mjs +0 -9
- package/dist/sk-SK.module.js +0 -9
- package/dist/sk-SK.module.js.map +0 -1
- package/dist/sl-SI.main.js +0 -7
- package/dist/sl-SI.main.js.map +0 -1
- package/dist/sl-SI.mjs +0 -9
- package/dist/sl-SI.module.js +0 -9
- package/dist/sl-SI.module.js.map +0 -1
- package/dist/sr-SP.main.js +0 -7
- package/dist/sr-SP.main.js.map +0 -1
- package/dist/sr-SP.mjs +0 -9
- package/dist/sr-SP.module.js +0 -9
- package/dist/sr-SP.module.js.map +0 -1
- package/dist/sv-SE.main.js +0 -7
- package/dist/sv-SE.main.js.map +0 -1
- package/dist/sv-SE.mjs +0 -9
- package/dist/sv-SE.module.js +0 -9
- package/dist/sv-SE.module.js.map +0 -1
- package/dist/tr-TR.main.js +0 -7
- package/dist/tr-TR.main.js.map +0 -1
- package/dist/tr-TR.mjs +0 -9
- package/dist/tr-TR.module.js +0 -9
- package/dist/tr-TR.module.js.map +0 -1
- package/dist/types.d.ts +0 -73
- package/dist/types.d.ts.map +0 -1
- package/dist/uk-UA.main.js +0 -7
- package/dist/uk-UA.main.js.map +0 -1
- package/dist/uk-UA.mjs +0 -9
- package/dist/uk-UA.module.js +0 -9
- package/dist/uk-UA.module.js.map +0 -1
- package/dist/useTag.main.js +0 -94
- package/dist/useTag.main.js.map +0 -1
- package/dist/useTag.mjs +0 -89
- package/dist/useTag.module.js +0 -89
- package/dist/useTag.module.js.map +0 -1
- package/dist/useTagGroup.main.js +0 -90
- package/dist/useTagGroup.main.js.map +0 -1
- package/dist/useTagGroup.mjs +0 -84
- package/dist/useTagGroup.module.js +0 -84
- package/dist/useTagGroup.module.js.map +0 -1
- package/dist/zh-CN.main.js +0 -7
- package/dist/zh-CN.main.js.map +0 -1
- package/dist/zh-CN.mjs +0 -9
- package/dist/zh-CN.module.js +0 -9
- package/dist/zh-CN.module.js.map +0 -1
- package/dist/zh-TW.main.js +0 -7
- package/dist/zh-TW.main.js.map +0 -1
- package/dist/zh-TW.mjs +0 -9
- package/dist/zh-TW.module.js +0 -9
- package/dist/zh-TW.module.js.map +0 -1
- package/src/useTag.ts +0 -119
- package/src/useTagGroup.ts +0 -128
package/dist/zh-TW.main.js
DELETED
package/dist/zh-TW.main.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAAA,iBAAiB;IAAG,qBAAqB,CAAC,gBAAE,CAAC;IAC3C,qBAAqB,CAAC,wEAAgB,CAAC;AACzC","sources":["packages/@react-aria/tag/intl/zh-TW.json"],"sourcesContent":["{\n \"removeButtonLabel\": \"移除\",\n \"removeDescription\": \"按 Delete 鍵以移除標記。\"\n}\n"],"names":[],"version":3,"file":"zh-TW.main.js.map"}
|
package/dist/zh-TW.mjs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
var $09cd168ab18773f4$exports = {};
|
|
2
|
-
$09cd168ab18773f4$exports = {
|
|
3
|
-
"removeButtonLabel": `\u{79FB}\u{9664}`,
|
|
4
|
-
"removeDescription": `\u{6309} Delete \u{9375}\u{4EE5}\u{79FB}\u{9664}\u{6A19}\u{8A18}\u{3002}`
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export {$09cd168ab18773f4$exports as default};
|
|
9
|
-
//# sourceMappingURL=zh-TW.module.js.map
|
package/dist/zh-TW.module.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
var $09cd168ab18773f4$exports = {};
|
|
2
|
-
$09cd168ab18773f4$exports = {
|
|
3
|
-
"removeButtonLabel": `\u{79FB}\u{9664}`,
|
|
4
|
-
"removeDescription": `\u{6309} Delete \u{9375}\u{4EE5}\u{79FB}\u{9664}\u{6A19}\u{8A18}\u{3002}`
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export {$09cd168ab18773f4$exports as default};
|
|
9
|
-
//# sourceMappingURL=zh-TW.module.js.map
|
package/dist/zh-TW.module.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";AAAA,4BAAiB;IAAG,qBAAqB,CAAC,gBAAE,CAAC;IAC3C,qBAAqB,CAAC,wEAAgB,CAAC;AACzC","sources":["packages/@react-aria/tag/intl/zh-TW.json"],"sourcesContent":["{\n \"removeButtonLabel\": \"移除\",\n \"removeDescription\": \"按 Delete 鍵以移除標記。\"\n}\n"],"names":[],"version":3,"file":"zh-TW.module.js.map"}
|
package/src/useTag.ts
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {AriaButtonProps} from '@react-types/button';
|
|
14
|
-
import {DOMAttributes, FocusableElement, Node, RefObject} from '@react-types/shared';
|
|
15
|
-
import {filterDOMProps, mergeProps, useDescription, useId, useSyntheticLinkProps} from '@react-aria/utils';
|
|
16
|
-
import {hookData} from './useTagGroup';
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
import intlMessages from '../intl/*.json';
|
|
19
|
-
import {KeyboardEvent} from 'react';
|
|
20
|
-
import type {ListState} from '@react-stately/list';
|
|
21
|
-
import {SelectableItemStates} from '@react-aria/selection';
|
|
22
|
-
import {useFocusable, useInteractionModality} from '@react-aria/interactions';
|
|
23
|
-
import {useGridListItem} from '@react-aria/gridlist';
|
|
24
|
-
import {useLocalizedStringFormatter} from '@react-aria/i18n';
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export interface TagAria extends Omit<SelectableItemStates, 'hasAction'> {
|
|
28
|
-
/** Props for the tag row element. */
|
|
29
|
-
rowProps: DOMAttributes,
|
|
30
|
-
/** Props for the tag cell element. */
|
|
31
|
-
gridCellProps: DOMAttributes,
|
|
32
|
-
/** Props for the tag remove button. */
|
|
33
|
-
removeButtonProps: AriaButtonProps,
|
|
34
|
-
/** Whether the tag can be removed. */
|
|
35
|
-
allowsRemoving: boolean
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface AriaTagProps<T> {
|
|
39
|
-
/** An object representing the tag. Contains all the relevant information that makes up the tag. */
|
|
40
|
-
item: Node<T>
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Provides the behavior and accessibility implementation for a tag component.
|
|
45
|
-
* @param props - Props to be applied to the tag.
|
|
46
|
-
* @param state - State for the tag group, as returned by `useListState`.
|
|
47
|
-
* @param ref - A ref to a DOM element for the tag.
|
|
48
|
-
*/
|
|
49
|
-
export function useTag<T>(props: AriaTagProps<T>, state: ListState<T>, ref: RefObject<FocusableElement | null>): TagAria {
|
|
50
|
-
let {item} = props;
|
|
51
|
-
let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/tag');
|
|
52
|
-
let buttonId = useId();
|
|
53
|
-
|
|
54
|
-
let {onRemove} = hookData.get(state) || {};
|
|
55
|
-
let {rowProps, gridCellProps, ...states} = useGridListItem({
|
|
56
|
-
node: item
|
|
57
|
-
}, state, ref);
|
|
58
|
-
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
60
|
-
let {descriptionProps: _, ...stateWithoutDescription} = states;
|
|
61
|
-
|
|
62
|
-
let isDisabled = state.disabledKeys.has(item.key) || item.props.isDisabled;
|
|
63
|
-
let onKeyDown = (e: KeyboardEvent) => {
|
|
64
|
-
if (e.key === 'Delete' || e.key === 'Backspace') {
|
|
65
|
-
if (isDisabled) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
e.preventDefault();
|
|
70
|
-
if (state.selectionManager.isSelected(item.key)) {
|
|
71
|
-
onRemove?.(new Set(state.selectionManager.selectedKeys));
|
|
72
|
-
} else {
|
|
73
|
-
onRemove?.(new Set([item.key]));
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
let modality = useInteractionModality();
|
|
79
|
-
if (modality === 'virtual' && (typeof window !== 'undefined' && 'ontouchstart' in window)) {
|
|
80
|
-
modality = 'pointer';
|
|
81
|
-
}
|
|
82
|
-
let description = onRemove && (modality === 'keyboard' || modality === 'virtual') ? stringFormatter.format('removeDescription') : '';
|
|
83
|
-
let descProps = useDescription(description);
|
|
84
|
-
|
|
85
|
-
let isItemFocused = item.key === state.selectionManager.focusedKey;
|
|
86
|
-
let isFocused = state.selectionManager.focusedKey != null;
|
|
87
|
-
let tabIndex = -1;
|
|
88
|
-
if (!isDisabled && (isItemFocused || !isFocused)) {
|
|
89
|
-
tabIndex = 0;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
let domProps = filterDOMProps(item.props);
|
|
93
|
-
let linkProps = useSyntheticLinkProps(item.props);
|
|
94
|
-
let {focusableProps} = useFocusable({
|
|
95
|
-
...item.props,
|
|
96
|
-
isDisabled
|
|
97
|
-
}, ref);
|
|
98
|
-
|
|
99
|
-
return {
|
|
100
|
-
removeButtonProps: {
|
|
101
|
-
'aria-label': stringFormatter.format('removeButtonLabel'),
|
|
102
|
-
'aria-labelledby': `${buttonId} ${rowProps.id}`,
|
|
103
|
-
isDisabled,
|
|
104
|
-
id: buttonId,
|
|
105
|
-
onPress: () => onRemove ? onRemove(new Set([item.key])) : null
|
|
106
|
-
},
|
|
107
|
-
rowProps: mergeProps(focusableProps, rowProps, domProps, linkProps, {
|
|
108
|
-
tabIndex,
|
|
109
|
-
onKeyDown: onRemove ? onKeyDown : undefined,
|
|
110
|
-
'aria-describedby': descProps['aria-describedby']
|
|
111
|
-
}),
|
|
112
|
-
gridCellProps: mergeProps(gridCellProps, {
|
|
113
|
-
'aria-errormessage': props['aria-errormessage'],
|
|
114
|
-
'aria-label': props['aria-label']
|
|
115
|
-
}),
|
|
116
|
-
...stateWithoutDescription,
|
|
117
|
-
allowsRemoving: !!onRemove
|
|
118
|
-
};
|
|
119
|
-
}
|
package/src/useTagGroup.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {AriaGridListProps, useGridList} from '@react-aria/gridlist';
|
|
14
|
-
import {AriaLabelingProps, CollectionBase, DOMAttributes, DOMProps, HelpTextProps, Key, KeyboardDelegate, LabelableProps, MultipleSelection, RefObject, SelectionBehavior} from '@react-types/shared';
|
|
15
|
-
import {filterDOMProps, mergeProps} from '@react-aria/utils';
|
|
16
|
-
import {ListKeyboardDelegate} from '@react-aria/selection';
|
|
17
|
-
import type {ListState} from '@react-stately/list';
|
|
18
|
-
import {ReactNode, useEffect, useRef, useState} from 'react';
|
|
19
|
-
import {useField} from '@react-aria/label';
|
|
20
|
-
import {useFocusWithin} from '@react-aria/interactions';
|
|
21
|
-
import {useLocale} from '@react-aria/i18n';
|
|
22
|
-
|
|
23
|
-
export interface TagGroupAria {
|
|
24
|
-
/** Props for the tag grouping element. */
|
|
25
|
-
gridProps: DOMAttributes,
|
|
26
|
-
/** Props for the tag group's visible label (if any). */
|
|
27
|
-
labelProps: DOMAttributes,
|
|
28
|
-
/** Props for the tag group description element, if any. */
|
|
29
|
-
descriptionProps: DOMAttributes,
|
|
30
|
-
/** Props for the tag group error message element, if any. */
|
|
31
|
-
errorMessageProps: DOMAttributes
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface AriaTagGroupProps<T> extends CollectionBase<T>, MultipleSelection, Pick<AriaGridListProps<T>, 'escapeKeyBehavior'>, DOMProps, LabelableProps, AriaLabelingProps, Omit<HelpTextProps, 'errorMessage'> {
|
|
35
|
-
/** How multiple selection should behave in the collection. */
|
|
36
|
-
selectionBehavior?: SelectionBehavior,
|
|
37
|
-
/** Whether selection should occur on press up instead of press down. */
|
|
38
|
-
shouldSelectOnPressUp?: boolean,
|
|
39
|
-
/** Handler that is called when a user deletes a tag. */
|
|
40
|
-
onRemove?: (keys: Set<Key>) => void,
|
|
41
|
-
/** An error message for the field. */
|
|
42
|
-
errorMessage?: ReactNode,
|
|
43
|
-
/**
|
|
44
|
-
* Whether pressing the escape key should clear selection in the TagGroup or not.
|
|
45
|
-
*
|
|
46
|
-
* Most experiences should not modify this option as it eliminates a keyboard user's ability to
|
|
47
|
-
* easily clear selection. Only use if the escape key is being handled externally or should not
|
|
48
|
-
* trigger selection clearing contextually.
|
|
49
|
-
* @default 'clearSelection'
|
|
50
|
-
*/
|
|
51
|
-
escapeKeyBehavior?: 'clearSelection' | 'none'
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export interface AriaTagGroupOptions<T> extends Omit<AriaTagGroupProps<T>, 'children'> {
|
|
55
|
-
/**
|
|
56
|
-
* An optional keyboard delegate to handle arrow key navigation,
|
|
57
|
-
* to override the default.
|
|
58
|
-
*/
|
|
59
|
-
keyboardDelegate?: KeyboardDelegate
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
interface HookData {
|
|
63
|
-
onRemove?: (keys: Set<Key>) => void
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export const hookData: WeakMap<ListState<any>, HookData> = new WeakMap<ListState<any>, HookData>();
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Provides the behavior and accessibility implementation for a tag group component.
|
|
70
|
-
* A tag group is a focusable list of labels, categories, keywords, filters, or other items, with support for keyboard navigation, selection, and removal.
|
|
71
|
-
* @param props - Props to be applied to the tag group.
|
|
72
|
-
* @param state - State for the tag group, as returned by `useListState`.
|
|
73
|
-
* @param ref - A ref to a DOM element for the tag group.
|
|
74
|
-
*/
|
|
75
|
-
export function useTagGroup<T>(props: AriaTagGroupOptions<T>, state: ListState<T>, ref: RefObject<HTMLElement | null>): TagGroupAria {
|
|
76
|
-
let {direction} = useLocale();
|
|
77
|
-
let keyboardDelegate = props.keyboardDelegate || new ListKeyboardDelegate({
|
|
78
|
-
collection: state.collection,
|
|
79
|
-
ref,
|
|
80
|
-
orientation: 'horizontal',
|
|
81
|
-
direction,
|
|
82
|
-
disabledKeys: state.disabledKeys,
|
|
83
|
-
disabledBehavior: state.selectionManager.disabledBehavior
|
|
84
|
-
});
|
|
85
|
-
let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({
|
|
86
|
-
...props,
|
|
87
|
-
labelElementType: 'span'
|
|
88
|
-
});
|
|
89
|
-
let {gridProps} = useGridList({
|
|
90
|
-
...props,
|
|
91
|
-
...fieldProps,
|
|
92
|
-
keyboardDelegate,
|
|
93
|
-
shouldFocusWrap: true,
|
|
94
|
-
linkBehavior: 'override',
|
|
95
|
-
keyboardNavigationBehavior: 'tab'
|
|
96
|
-
}, state, ref);
|
|
97
|
-
|
|
98
|
-
let [isFocusWithin, setFocusWithin] = useState(false);
|
|
99
|
-
let {focusWithinProps} = useFocusWithin({
|
|
100
|
-
onFocusWithinChange: setFocusWithin
|
|
101
|
-
});
|
|
102
|
-
let domProps = filterDOMProps(props);
|
|
103
|
-
|
|
104
|
-
// If the last tag is removed, focus the container.
|
|
105
|
-
let prevCount = useRef(state.collection.size);
|
|
106
|
-
useEffect(() => {
|
|
107
|
-
if (ref.current && prevCount.current > 0 && state.collection.size === 0 && isFocusWithin) {
|
|
108
|
-
ref.current.focus();
|
|
109
|
-
}
|
|
110
|
-
prevCount.current = state.collection.size;
|
|
111
|
-
}, [state.collection.size, isFocusWithin, ref]);
|
|
112
|
-
|
|
113
|
-
hookData.set(state, {onRemove: props.onRemove});
|
|
114
|
-
|
|
115
|
-
return {
|
|
116
|
-
gridProps: mergeProps(gridProps, domProps, {
|
|
117
|
-
role: state.collection.size ? 'grid' : 'group',
|
|
118
|
-
'aria-atomic': false,
|
|
119
|
-
'aria-relevant': 'additions',
|
|
120
|
-
'aria-live': isFocusWithin ? 'polite' : 'off',
|
|
121
|
-
...focusWithinProps,
|
|
122
|
-
...fieldProps
|
|
123
|
-
}),
|
|
124
|
-
labelProps,
|
|
125
|
-
descriptionProps,
|
|
126
|
-
errorMessageProps
|
|
127
|
-
};
|
|
128
|
-
}
|