@react-aria/tag 3.3.3 → 3.4.1
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 -257
- package/dist/intlStrings.main.js +108 -0
- package/dist/intlStrings.main.js.map +1 -0
- package/dist/intlStrings.mjs +110 -0
- package/dist/intlStrings.module.js +110 -0
- package/dist/intlStrings.module.js.map +1 -0
- package/dist/main.js +4 -259
- package/dist/main.js.map +1 -1
- package/dist/module.js +2 -257
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/useTag.main.js +88 -0
- package/dist/useTag.main.js.map +1 -0
- package/dist/useTag.mjs +83 -0
- package/dist/useTag.module.js +83 -0
- package/dist/useTag.module.js.map +1 -0
- package/dist/useTagGroup.main.js +89 -0
- package/dist/useTagGroup.main.js.map +1 -0
- package/dist/useTagGroup.mjs +83 -0
- package/dist/useTagGroup.module.js +83 -0
- package/dist/useTagGroup.module.js.map +1 -0
- package/package.json +11 -11
- package/src/useTagGroup.ts +2 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
var $09704b0efefe5140$exports = require("./useTagGroup.main.js");
|
|
2
|
+
var $b6a2538ff098a9ff$exports = require("./intlStrings.main.js");
|
|
3
|
+
var $8p8DL$reactariautils = require("@react-aria/utils");
|
|
4
|
+
var $8p8DL$reactariagridlist = require("@react-aria/gridlist");
|
|
5
|
+
var $8p8DL$reactariainteractions = require("@react-aria/interactions");
|
|
6
|
+
var $8p8DL$reactariai18n = require("@react-aria/i18n");
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
function $parcel$interopDefault(a) {
|
|
10
|
+
return a && a.__esModule ? a.default : a;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function $parcel$export(e, n, v, s) {
|
|
14
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
$parcel$export(module.exports, "useTag", () => $a442534c81d8ad16$export$3f568fff7dff2f03);
|
|
18
|
+
/*
|
|
19
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
20
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
21
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
22
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
23
|
+
*
|
|
24
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
25
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
26
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
27
|
+
* governing permissions and limitations under the License.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
function $a442534c81d8ad16$export$3f568fff7dff2f03(props, state, ref) {
|
|
35
|
+
let { item: item } = props;
|
|
36
|
+
let stringFormatter = (0, $8p8DL$reactariai18n.useLocalizedStringFormatter)((0, ($parcel$interopDefault($b6a2538ff098a9ff$exports))), '@react-aria/tag');
|
|
37
|
+
let buttonId = (0, $8p8DL$reactariautils.useId)();
|
|
38
|
+
let { onRemove: onRemove } = (0, $09704b0efefe5140$exports.hookData).get(state) || {};
|
|
39
|
+
let { rowProps: rowProps, gridCellProps: gridCellProps, ...states } = (0, $8p8DL$reactariagridlist.useGridListItem)({
|
|
40
|
+
node: item
|
|
41
|
+
}, state, ref);
|
|
42
|
+
// We want the group to handle keyboard navigation between tags.
|
|
43
|
+
delete rowProps.onKeyDownCapture;
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
45
|
+
let { descriptionProps: _, ...stateWithoutDescription } = states;
|
|
46
|
+
let onKeyDown = (e)=>{
|
|
47
|
+
if (e.key === 'Delete' || e.key === 'Backspace') {
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
if (state.selectionManager.isSelected(item.key)) onRemove === null || onRemove === void 0 ? void 0 : onRemove(new Set(state.selectionManager.selectedKeys));
|
|
50
|
+
else onRemove === null || onRemove === void 0 ? void 0 : onRemove(new Set([
|
|
51
|
+
item.key
|
|
52
|
+
]));
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
let modality = (0, $8p8DL$reactariainteractions.useInteractionModality)();
|
|
56
|
+
if (modality === 'virtual' && typeof window !== 'undefined' && 'ontouchstart' in window) modality = 'pointer';
|
|
57
|
+
let description = onRemove && (modality === 'keyboard' || modality === 'virtual') ? stringFormatter.format('removeDescription') : '';
|
|
58
|
+
let descProps = (0, $8p8DL$reactariautils.useDescription)(description);
|
|
59
|
+
let isFocused = item.key === state.selectionManager.focusedKey;
|
|
60
|
+
// @ts-ignore - data attributes are ok but TS doesn't know about them.
|
|
61
|
+
let domProps = (0, $8p8DL$reactariautils.filterDOMProps)(item.props);
|
|
62
|
+
let linkProps = (0, $8p8DL$reactariautils.getSyntheticLinkProps)(item.props);
|
|
63
|
+
return {
|
|
64
|
+
removeButtonProps: {
|
|
65
|
+
'aria-label': stringFormatter.format('removeButtonLabel'),
|
|
66
|
+
'aria-labelledby': `${buttonId} ${rowProps.id}`,
|
|
67
|
+
id: buttonId,
|
|
68
|
+
onPress: ()=>onRemove ? onRemove(new Set([
|
|
69
|
+
item.key
|
|
70
|
+
])) : null,
|
|
71
|
+
excludeFromTabOrder: true
|
|
72
|
+
},
|
|
73
|
+
rowProps: (0, $8p8DL$reactariautils.mergeProps)(rowProps, domProps, linkProps, {
|
|
74
|
+
tabIndex: isFocused || state.selectionManager.focusedKey == null ? 0 : -1,
|
|
75
|
+
onKeyDown: onRemove ? onKeyDown : undefined,
|
|
76
|
+
'aria-describedby': descProps['aria-describedby']
|
|
77
|
+
}),
|
|
78
|
+
gridCellProps: (0, $8p8DL$reactariautils.mergeProps)(gridCellProps, {
|
|
79
|
+
'aria-errormessage': props['aria-errormessage'],
|
|
80
|
+
'aria-label': props['aria-label']
|
|
81
|
+
}),
|
|
82
|
+
...stateWithoutDescription,
|
|
83
|
+
allowsRemoving: !!onRemove
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
//# sourceMappingURL=useTag.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAsCM,SAAS,0CAAU,KAAsB,EAAE,KAAmB,EAAE,GAAgC;IACrG,IAAI,QAAC,IAAI,EAAC,GAAG;IACb,IAAI,kBAAkB,CAAA,GAAA,gDAA0B,EAAE,CAAA,GAAA,mDAAW,GAAG;IAChE,IAAI,WAAW,CAAA,GAAA,2BAAI;IAEnB,IAAI,YAAC,QAAQ,EAAC,GAAG,CAAA,GAAA,kCAAO,EAAE,GAAG,CAAC,UAAU,CAAC;IACzC,IAAI,YAAC,QAAQ,iBAAE,aAAa,EAAE,GAAG,QAAO,GAAG,CAAA,GAAA,wCAAc,EAAE;QACzD,MAAM;IACR,GAAG,OAAO;IAEV,gEAAgE;IAChE,OAAO,SAAS,gBAAgB;IAChC,6DAA6D;IAC7D,IAAI,EAAC,kBAAkB,CAAC,EAAE,GAAG,yBAAwB,GAAG;IAExD,IAAI,YAAY,CAAC;QACf,IAAI,EAAE,GAAG,KAAK,YAAY,EAAE,GAAG,KAAK,aAAa;YAC/C,EAAE,cAAc;YAChB,IAAI,MAAM,gBAAgB,CAAC,UAAU,CAAC,KAAK,GAAG,GAC5C,qBAAA,+BAAA,SAAW,IAAI,IAAI,MAAM,gBAAgB,CAAC,YAAY;iBAEtD,qBAAA,+BAAA,SAAW,IAAI,IAAI;gBAAC,KAAK,GAAG;aAAC;QAEjC;IACF;IAEA,IAAI,WAAW,CAAA,GAAA,mDAAqB;IACpC,IAAI,aAAa,aAAe,OAAO,WAAW,eAAe,kBAAkB,QACjF,WAAW;IAEb,IAAI,cAAc,YAAa,CAAA,aAAa,cAAc,aAAa,SAAQ,IAAK,gBAAgB,MAAM,CAAC,uBAAuB;IAClI,IAAI,YAAY,CAAA,GAAA,oCAAa,EAAE;IAE/B,IAAI,YAAY,KAAK,GAAG,KAAK,MAAM,gBAAgB,CAAC,UAAU;IAC9D,sEAAsE;IACtE,IAAI,WAAW,CAAA,GAAA,oCAAa,EAAE,KAAK,KAAK;IACxC,IAAI,YAAY,CAAA,GAAA,2CAAoB,EAAE,KAAK,KAAK;IAChD,OAAO;QACL,mBAAmB;YACjB,cAAc,gBAAgB,MAAM,CAAC;YACrC,mBAAmB,CAAC,EAAE,SAAS,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;YAC/C,IAAI;YACJ,SAAS,IAAM,WAAW,SAAS,IAAI,IAAI;oBAAC,KAAK,GAAG;iBAAC,KAAK;YAC1D,qBAAqB;QACvB;QACA,UAAU,CAAA,GAAA,gCAAS,EAAE,UAAU,UAAU,WAAW;YAClD,UAAU,AAAC,aAAa,MAAM,gBAAgB,CAAC,UAAU,IAAI,OAAQ,IAAI;YACzE,WAAW,WAAW,YAAY;YAClC,oBAAoB,SAAS,CAAC,mBAAmB;QACnD;QACA,eAAe,CAAA,GAAA,gCAAS,EAAE,eAAe;YACvC,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,cAAc,KAAK,CAAC,aAAa;QACnC;QACA,GAAG,uBAAuB;QAC1B,gBAAgB,CAAC,CAAC;IACpB;AACF","sources":["packages/@react-aria/tag/src/useTag.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 {AriaButtonProps} from '@react-types/button';\nimport {DOMAttributes, FocusableElement, Node} from '@react-types/shared';\nimport {filterDOMProps, getSyntheticLinkProps, mergeProps, useDescription, useId} from '@react-aria/utils';\nimport {hookData} from './useTagGroup';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {KeyboardEvent, RefObject} from 'react';\nimport type {ListState} from '@react-stately/list';\nimport {SelectableItemStates} from '@react-aria/selection';\nimport {useGridListItem} from '@react-aria/gridlist';\nimport {useInteractionModality} from '@react-aria/interactions';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\n\nexport interface TagAria extends Omit<SelectableItemStates, 'hasAction'> {\n /** Props for the tag row element. */\n rowProps: DOMAttributes,\n /** Props for the tag cell element. */\n gridCellProps: DOMAttributes,\n /** Props for the tag remove button. */\n removeButtonProps: AriaButtonProps,\n /** Whether the tag can be removed. */\n allowsRemoving: boolean\n}\n\nexport interface AriaTagProps<T> {\n /** An object representing the tag. Contains all the relevant information that makes up the tag. */\n item: Node<T>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a tag component.\n * @param props - Props to be applied to the tag.\n * @param state - State for the tag group, as returned by `useListState`.\n * @param ref - A ref to a DOM element for the tag.\n */\nexport function useTag<T>(props: AriaTagProps<T>, state: ListState<T>, ref: RefObject<FocusableElement>): TagAria {\n let {item} = props;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/tag');\n let buttonId = useId();\n\n let {onRemove} = hookData.get(state) || {};\n let {rowProps, gridCellProps, ...states} = useGridListItem({\n node: item\n }, state, ref);\n\n // We want the group to handle keyboard navigation between tags.\n delete rowProps.onKeyDownCapture;\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n let {descriptionProps: _, ...stateWithoutDescription} = states;\n\n let onKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'Delete' || e.key === 'Backspace') {\n e.preventDefault();\n if (state.selectionManager.isSelected(item.key)) {\n onRemove?.(new Set(state.selectionManager.selectedKeys));\n } else {\n onRemove?.(new Set([item.key]));\n }\n }\n };\n\n let modality = useInteractionModality();\n if (modality === 'virtual' && (typeof window !== 'undefined' && 'ontouchstart' in window)) {\n modality = 'pointer';\n }\n let description = onRemove && (modality === 'keyboard' || modality === 'virtual') ? stringFormatter.format('removeDescription') : '';\n let descProps = useDescription(description);\n\n let isFocused = item.key === state.selectionManager.focusedKey;\n // @ts-ignore - data attributes are ok but TS doesn't know about them.\n let domProps = filterDOMProps(item.props);\n let linkProps = getSyntheticLinkProps(item.props);\n return {\n removeButtonProps: {\n 'aria-label': stringFormatter.format('removeButtonLabel'),\n 'aria-labelledby': `${buttonId} ${rowProps.id}`,\n id: buttonId,\n onPress: () => onRemove ? onRemove(new Set([item.key])) : null,\n excludeFromTabOrder: true\n },\n rowProps: mergeProps(rowProps, domProps, linkProps, {\n tabIndex: (isFocused || state.selectionManager.focusedKey == null) ? 0 : -1,\n onKeyDown: onRemove ? onKeyDown : undefined,\n 'aria-describedby': descProps['aria-describedby']\n }),\n gridCellProps: mergeProps(gridCellProps, {\n 'aria-errormessage': props['aria-errormessage'],\n 'aria-label': props['aria-label']\n }),\n ...stateWithoutDescription,\n allowsRemoving: !!onRemove\n };\n}\n"],"names":[],"version":3,"file":"useTag.main.js.map"}
|
package/dist/useTag.mjs
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {hookData as $d7323bca8d074eeb$export$653eddfc964b0f8a} from "./useTagGroup.mjs";
|
|
2
|
+
import $ioKwR$intlStringsmodulejs from "./intlStrings.mjs";
|
|
3
|
+
import {useId as $ioKwR$useId, useDescription as $ioKwR$useDescription, filterDOMProps as $ioKwR$filterDOMProps, getSyntheticLinkProps as $ioKwR$getSyntheticLinkProps, mergeProps as $ioKwR$mergeProps} from "@react-aria/utils";
|
|
4
|
+
import {useGridListItem as $ioKwR$useGridListItem} from "@react-aria/gridlist";
|
|
5
|
+
import {useInteractionModality as $ioKwR$useInteractionModality} from "@react-aria/interactions";
|
|
6
|
+
import {useLocalizedStringFormatter as $ioKwR$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
function $parcel$interopDefault(a) {
|
|
10
|
+
return a && a.__esModule ? a.default : a;
|
|
11
|
+
}
|
|
12
|
+
/*
|
|
13
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
14
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
15
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
16
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
19
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
20
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
21
|
+
* governing permissions and limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
function $fc6126c82a4601f1$export$3f568fff7dff2f03(props, state, ref) {
|
|
29
|
+
let { item: item } = props;
|
|
30
|
+
let stringFormatter = (0, $ioKwR$useLocalizedStringFormatter)((0, ($parcel$interopDefault($ioKwR$intlStringsmodulejs))), '@react-aria/tag');
|
|
31
|
+
let buttonId = (0, $ioKwR$useId)();
|
|
32
|
+
let { onRemove: onRemove } = (0, $d7323bca8d074eeb$export$653eddfc964b0f8a).get(state) || {};
|
|
33
|
+
let { rowProps: rowProps, gridCellProps: gridCellProps, ...states } = (0, $ioKwR$useGridListItem)({
|
|
34
|
+
node: item
|
|
35
|
+
}, state, ref);
|
|
36
|
+
// We want the group to handle keyboard navigation between tags.
|
|
37
|
+
delete rowProps.onKeyDownCapture;
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
39
|
+
let { descriptionProps: _, ...stateWithoutDescription } = states;
|
|
40
|
+
let onKeyDown = (e)=>{
|
|
41
|
+
if (e.key === 'Delete' || e.key === 'Backspace') {
|
|
42
|
+
e.preventDefault();
|
|
43
|
+
if (state.selectionManager.isSelected(item.key)) onRemove === null || onRemove === void 0 ? void 0 : onRemove(new Set(state.selectionManager.selectedKeys));
|
|
44
|
+
else onRemove === null || onRemove === void 0 ? void 0 : onRemove(new Set([
|
|
45
|
+
item.key
|
|
46
|
+
]));
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
let modality = (0, $ioKwR$useInteractionModality)();
|
|
50
|
+
if (modality === 'virtual' && typeof window !== 'undefined' && 'ontouchstart' in window) modality = 'pointer';
|
|
51
|
+
let description = onRemove && (modality === 'keyboard' || modality === 'virtual') ? stringFormatter.format('removeDescription') : '';
|
|
52
|
+
let descProps = (0, $ioKwR$useDescription)(description);
|
|
53
|
+
let isFocused = item.key === state.selectionManager.focusedKey;
|
|
54
|
+
// @ts-ignore - data attributes are ok but TS doesn't know about them.
|
|
55
|
+
let domProps = (0, $ioKwR$filterDOMProps)(item.props);
|
|
56
|
+
let linkProps = (0, $ioKwR$getSyntheticLinkProps)(item.props);
|
|
57
|
+
return {
|
|
58
|
+
removeButtonProps: {
|
|
59
|
+
'aria-label': stringFormatter.format('removeButtonLabel'),
|
|
60
|
+
'aria-labelledby': `${buttonId} ${rowProps.id}`,
|
|
61
|
+
id: buttonId,
|
|
62
|
+
onPress: ()=>onRemove ? onRemove(new Set([
|
|
63
|
+
item.key
|
|
64
|
+
])) : null,
|
|
65
|
+
excludeFromTabOrder: true
|
|
66
|
+
},
|
|
67
|
+
rowProps: (0, $ioKwR$mergeProps)(rowProps, domProps, linkProps, {
|
|
68
|
+
tabIndex: isFocused || state.selectionManager.focusedKey == null ? 0 : -1,
|
|
69
|
+
onKeyDown: onRemove ? onKeyDown : undefined,
|
|
70
|
+
'aria-describedby': descProps['aria-describedby']
|
|
71
|
+
}),
|
|
72
|
+
gridCellProps: (0, $ioKwR$mergeProps)(gridCellProps, {
|
|
73
|
+
'aria-errormessage': props['aria-errormessage'],
|
|
74
|
+
'aria-label': props['aria-label']
|
|
75
|
+
}),
|
|
76
|
+
...stateWithoutDescription,
|
|
77
|
+
allowsRemoving: !!onRemove
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
export {$fc6126c82a4601f1$export$3f568fff7dff2f03 as useTag};
|
|
83
|
+
//# sourceMappingURL=useTag.module.js.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {hookData as $d7323bca8d074eeb$export$653eddfc964b0f8a} from "./useTagGroup.module.js";
|
|
2
|
+
import $ioKwR$intlStringsmodulejs from "./intlStrings.module.js";
|
|
3
|
+
import {useId as $ioKwR$useId, useDescription as $ioKwR$useDescription, filterDOMProps as $ioKwR$filterDOMProps, getSyntheticLinkProps as $ioKwR$getSyntheticLinkProps, mergeProps as $ioKwR$mergeProps} from "@react-aria/utils";
|
|
4
|
+
import {useGridListItem as $ioKwR$useGridListItem} from "@react-aria/gridlist";
|
|
5
|
+
import {useInteractionModality as $ioKwR$useInteractionModality} from "@react-aria/interactions";
|
|
6
|
+
import {useLocalizedStringFormatter as $ioKwR$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
function $parcel$interopDefault(a) {
|
|
10
|
+
return a && a.__esModule ? a.default : a;
|
|
11
|
+
}
|
|
12
|
+
/*
|
|
13
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
14
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
15
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
16
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
19
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
20
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
21
|
+
* governing permissions and limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
function $fc6126c82a4601f1$export$3f568fff7dff2f03(props, state, ref) {
|
|
29
|
+
let { item: item } = props;
|
|
30
|
+
let stringFormatter = (0, $ioKwR$useLocalizedStringFormatter)((0, ($parcel$interopDefault($ioKwR$intlStringsmodulejs))), '@react-aria/tag');
|
|
31
|
+
let buttonId = (0, $ioKwR$useId)();
|
|
32
|
+
let { onRemove: onRemove } = (0, $d7323bca8d074eeb$export$653eddfc964b0f8a).get(state) || {};
|
|
33
|
+
let { rowProps: rowProps, gridCellProps: gridCellProps, ...states } = (0, $ioKwR$useGridListItem)({
|
|
34
|
+
node: item
|
|
35
|
+
}, state, ref);
|
|
36
|
+
// We want the group to handle keyboard navigation between tags.
|
|
37
|
+
delete rowProps.onKeyDownCapture;
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
39
|
+
let { descriptionProps: _, ...stateWithoutDescription } = states;
|
|
40
|
+
let onKeyDown = (e)=>{
|
|
41
|
+
if (e.key === 'Delete' || e.key === 'Backspace') {
|
|
42
|
+
e.preventDefault();
|
|
43
|
+
if (state.selectionManager.isSelected(item.key)) onRemove === null || onRemove === void 0 ? void 0 : onRemove(new Set(state.selectionManager.selectedKeys));
|
|
44
|
+
else onRemove === null || onRemove === void 0 ? void 0 : onRemove(new Set([
|
|
45
|
+
item.key
|
|
46
|
+
]));
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
let modality = (0, $ioKwR$useInteractionModality)();
|
|
50
|
+
if (modality === 'virtual' && typeof window !== 'undefined' && 'ontouchstart' in window) modality = 'pointer';
|
|
51
|
+
let description = onRemove && (modality === 'keyboard' || modality === 'virtual') ? stringFormatter.format('removeDescription') : '';
|
|
52
|
+
let descProps = (0, $ioKwR$useDescription)(description);
|
|
53
|
+
let isFocused = item.key === state.selectionManager.focusedKey;
|
|
54
|
+
// @ts-ignore - data attributes are ok but TS doesn't know about them.
|
|
55
|
+
let domProps = (0, $ioKwR$filterDOMProps)(item.props);
|
|
56
|
+
let linkProps = (0, $ioKwR$getSyntheticLinkProps)(item.props);
|
|
57
|
+
return {
|
|
58
|
+
removeButtonProps: {
|
|
59
|
+
'aria-label': stringFormatter.format('removeButtonLabel'),
|
|
60
|
+
'aria-labelledby': `${buttonId} ${rowProps.id}`,
|
|
61
|
+
id: buttonId,
|
|
62
|
+
onPress: ()=>onRemove ? onRemove(new Set([
|
|
63
|
+
item.key
|
|
64
|
+
])) : null,
|
|
65
|
+
excludeFromTabOrder: true
|
|
66
|
+
},
|
|
67
|
+
rowProps: (0, $ioKwR$mergeProps)(rowProps, domProps, linkProps, {
|
|
68
|
+
tabIndex: isFocused || state.selectionManager.focusedKey == null ? 0 : -1,
|
|
69
|
+
onKeyDown: onRemove ? onKeyDown : undefined,
|
|
70
|
+
'aria-describedby': descProps['aria-describedby']
|
|
71
|
+
}),
|
|
72
|
+
gridCellProps: (0, $ioKwR$mergeProps)(gridCellProps, {
|
|
73
|
+
'aria-errormessage': props['aria-errormessage'],
|
|
74
|
+
'aria-label': props['aria-label']
|
|
75
|
+
}),
|
|
76
|
+
...stateWithoutDescription,
|
|
77
|
+
allowsRemoving: !!onRemove
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
export {$fc6126c82a4601f1$export$3f568fff7dff2f03 as useTag};
|
|
83
|
+
//# sourceMappingURL=useTag.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAsCM,SAAS,0CAAU,KAAsB,EAAE,KAAmB,EAAE,GAAgC;IACrG,IAAI,QAAC,IAAI,EAAC,GAAG;IACb,IAAI,kBAAkB,CAAA,GAAA,kCAA0B,EAAE,CAAA,GAAA,oDAAW,GAAG;IAChE,IAAI,WAAW,CAAA,GAAA,YAAI;IAEnB,IAAI,YAAC,QAAQ,EAAC,GAAG,CAAA,GAAA,yCAAO,EAAE,GAAG,CAAC,UAAU,CAAC;IACzC,IAAI,YAAC,QAAQ,iBAAE,aAAa,EAAE,GAAG,QAAO,GAAG,CAAA,GAAA,sBAAc,EAAE;QACzD,MAAM;IACR,GAAG,OAAO;IAEV,gEAAgE;IAChE,OAAO,SAAS,gBAAgB;IAChC,6DAA6D;IAC7D,IAAI,EAAC,kBAAkB,CAAC,EAAE,GAAG,yBAAwB,GAAG;IAExD,IAAI,YAAY,CAAC;QACf,IAAI,EAAE,GAAG,KAAK,YAAY,EAAE,GAAG,KAAK,aAAa;YAC/C,EAAE,cAAc;YAChB,IAAI,MAAM,gBAAgB,CAAC,UAAU,CAAC,KAAK,GAAG,GAC5C,qBAAA,+BAAA,SAAW,IAAI,IAAI,MAAM,gBAAgB,CAAC,YAAY;iBAEtD,qBAAA,+BAAA,SAAW,IAAI,IAAI;gBAAC,KAAK,GAAG;aAAC;QAEjC;IACF;IAEA,IAAI,WAAW,CAAA,GAAA,6BAAqB;IACpC,IAAI,aAAa,aAAe,OAAO,WAAW,eAAe,kBAAkB,QACjF,WAAW;IAEb,IAAI,cAAc,YAAa,CAAA,aAAa,cAAc,aAAa,SAAQ,IAAK,gBAAgB,MAAM,CAAC,uBAAuB;IAClI,IAAI,YAAY,CAAA,GAAA,qBAAa,EAAE;IAE/B,IAAI,YAAY,KAAK,GAAG,KAAK,MAAM,gBAAgB,CAAC,UAAU;IAC9D,sEAAsE;IACtE,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE,KAAK,KAAK;IACxC,IAAI,YAAY,CAAA,GAAA,4BAAoB,EAAE,KAAK,KAAK;IAChD,OAAO;QACL,mBAAmB;YACjB,cAAc,gBAAgB,MAAM,CAAC;YACrC,mBAAmB,CAAC,EAAE,SAAS,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;YAC/C,IAAI;YACJ,SAAS,IAAM,WAAW,SAAS,IAAI,IAAI;oBAAC,KAAK,GAAG;iBAAC,KAAK;YAC1D,qBAAqB;QACvB;QACA,UAAU,CAAA,GAAA,iBAAS,EAAE,UAAU,UAAU,WAAW;YAClD,UAAU,AAAC,aAAa,MAAM,gBAAgB,CAAC,UAAU,IAAI,OAAQ,IAAI;YACzE,WAAW,WAAW,YAAY;YAClC,oBAAoB,SAAS,CAAC,mBAAmB;QACnD;QACA,eAAe,CAAA,GAAA,iBAAS,EAAE,eAAe;YACvC,qBAAqB,KAAK,CAAC,oBAAoB;YAC/C,cAAc,KAAK,CAAC,aAAa;QACnC;QACA,GAAG,uBAAuB;QAC1B,gBAAgB,CAAC,CAAC;IACpB;AACF","sources":["packages/@react-aria/tag/src/useTag.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 {AriaButtonProps} from '@react-types/button';\nimport {DOMAttributes, FocusableElement, Node} from '@react-types/shared';\nimport {filterDOMProps, getSyntheticLinkProps, mergeProps, useDescription, useId} from '@react-aria/utils';\nimport {hookData} from './useTagGroup';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {KeyboardEvent, RefObject} from 'react';\nimport type {ListState} from '@react-stately/list';\nimport {SelectableItemStates} from '@react-aria/selection';\nimport {useGridListItem} from '@react-aria/gridlist';\nimport {useInteractionModality} from '@react-aria/interactions';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\n\nexport interface TagAria extends Omit<SelectableItemStates, 'hasAction'> {\n /** Props for the tag row element. */\n rowProps: DOMAttributes,\n /** Props for the tag cell element. */\n gridCellProps: DOMAttributes,\n /** Props for the tag remove button. */\n removeButtonProps: AriaButtonProps,\n /** Whether the tag can be removed. */\n allowsRemoving: boolean\n}\n\nexport interface AriaTagProps<T> {\n /** An object representing the tag. Contains all the relevant information that makes up the tag. */\n item: Node<T>\n}\n\n/**\n * Provides the behavior and accessibility implementation for a tag component.\n * @param props - Props to be applied to the tag.\n * @param state - State for the tag group, as returned by `useListState`.\n * @param ref - A ref to a DOM element for the tag.\n */\nexport function useTag<T>(props: AriaTagProps<T>, state: ListState<T>, ref: RefObject<FocusableElement>): TagAria {\n let {item} = props;\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/tag');\n let buttonId = useId();\n\n let {onRemove} = hookData.get(state) || {};\n let {rowProps, gridCellProps, ...states} = useGridListItem({\n node: item\n }, state, ref);\n\n // We want the group to handle keyboard navigation between tags.\n delete rowProps.onKeyDownCapture;\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n let {descriptionProps: _, ...stateWithoutDescription} = states;\n\n let onKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'Delete' || e.key === 'Backspace') {\n e.preventDefault();\n if (state.selectionManager.isSelected(item.key)) {\n onRemove?.(new Set(state.selectionManager.selectedKeys));\n } else {\n onRemove?.(new Set([item.key]));\n }\n }\n };\n\n let modality = useInteractionModality();\n if (modality === 'virtual' && (typeof window !== 'undefined' && 'ontouchstart' in window)) {\n modality = 'pointer';\n }\n let description = onRemove && (modality === 'keyboard' || modality === 'virtual') ? stringFormatter.format('removeDescription') : '';\n let descProps = useDescription(description);\n\n let isFocused = item.key === state.selectionManager.focusedKey;\n // @ts-ignore - data attributes are ok but TS doesn't know about them.\n let domProps = filterDOMProps(item.props);\n let linkProps = getSyntheticLinkProps(item.props);\n return {\n removeButtonProps: {\n 'aria-label': stringFormatter.format('removeButtonLabel'),\n 'aria-labelledby': `${buttonId} ${rowProps.id}`,\n id: buttonId,\n onPress: () => onRemove ? onRemove(new Set([item.key])) : null,\n excludeFromTabOrder: true\n },\n rowProps: mergeProps(rowProps, domProps, linkProps, {\n tabIndex: (isFocused || state.selectionManager.focusedKey == null) ? 0 : -1,\n onKeyDown: onRemove ? onKeyDown : undefined,\n 'aria-describedby': descProps['aria-describedby']\n }),\n gridCellProps: mergeProps(gridCellProps, {\n 'aria-errormessage': props['aria-errormessage'],\n 'aria-label': props['aria-label']\n }),\n ...stateWithoutDescription,\n allowsRemoving: !!onRemove\n };\n}\n"],"names":[],"version":3,"file":"useTag.module.js.map"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
var $jLhmn$reactariautils = require("@react-aria/utils");
|
|
2
|
+
var $jLhmn$reactariaselection = require("@react-aria/selection");
|
|
3
|
+
var $jLhmn$react = require("react");
|
|
4
|
+
var $jLhmn$reactarialabel = require("@react-aria/label");
|
|
5
|
+
var $jLhmn$reactariainteractions = require("@react-aria/interactions");
|
|
6
|
+
var $jLhmn$reactariagridlist = require("@react-aria/gridlist");
|
|
7
|
+
var $jLhmn$reactariai18n = require("@react-aria/i18n");
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
function $parcel$export(e, n, v, s) {
|
|
11
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
$parcel$export(module.exports, "hookData", () => $09704b0efefe5140$export$653eddfc964b0f8a);
|
|
15
|
+
$parcel$export(module.exports, "useTagGroup", () => $09704b0efefe5140$export$4f8b5cda58b7e8ff);
|
|
16
|
+
/*
|
|
17
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
18
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
19
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
20
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
21
|
+
*
|
|
22
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
23
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
24
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
25
|
+
* governing permissions and limitations under the License.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
const $09704b0efefe5140$export$653eddfc964b0f8a = new WeakMap();
|
|
34
|
+
function $09704b0efefe5140$export$4f8b5cda58b7e8ff(props, state, ref) {
|
|
35
|
+
let { direction: direction } = (0, $jLhmn$reactariai18n.useLocale)();
|
|
36
|
+
let keyboardDelegate = props.keyboardDelegate || new (0, $jLhmn$reactariaselection.ListKeyboardDelegate)({
|
|
37
|
+
collection: state.collection,
|
|
38
|
+
ref: ref,
|
|
39
|
+
orientation: 'horizontal',
|
|
40
|
+
direction: direction,
|
|
41
|
+
disabledKeys: state.disabledKeys,
|
|
42
|
+
disabledBehavior: state.selectionManager.disabledBehavior
|
|
43
|
+
});
|
|
44
|
+
let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $jLhmn$reactarialabel.useField)({
|
|
45
|
+
...props,
|
|
46
|
+
labelElementType: 'span'
|
|
47
|
+
});
|
|
48
|
+
let { gridProps: gridProps } = (0, $jLhmn$reactariagridlist.useGridList)({
|
|
49
|
+
...props,
|
|
50
|
+
...fieldProps,
|
|
51
|
+
keyboardDelegate: keyboardDelegate,
|
|
52
|
+
shouldFocusWrap: true,
|
|
53
|
+
linkBehavior: 'override'
|
|
54
|
+
}, state, ref);
|
|
55
|
+
let [isFocusWithin, setFocusWithin] = (0, $jLhmn$react.useState)(false);
|
|
56
|
+
let { focusWithinProps: focusWithinProps } = (0, $jLhmn$reactariainteractions.useFocusWithin)({
|
|
57
|
+
onFocusWithinChange: setFocusWithin
|
|
58
|
+
});
|
|
59
|
+
let domProps = (0, $jLhmn$reactariautils.filterDOMProps)(props);
|
|
60
|
+
// If the last tag is removed, focus the container.
|
|
61
|
+
let prevCount = (0, $jLhmn$react.useRef)(state.collection.size);
|
|
62
|
+
(0, $jLhmn$react.useEffect)(()=>{
|
|
63
|
+
if (ref.current && prevCount.current > 0 && state.collection.size === 0 && isFocusWithin) ref.current.focus();
|
|
64
|
+
prevCount.current = state.collection.size;
|
|
65
|
+
}, [
|
|
66
|
+
state.collection.size,
|
|
67
|
+
isFocusWithin,
|
|
68
|
+
ref
|
|
69
|
+
]);
|
|
70
|
+
$09704b0efefe5140$export$653eddfc964b0f8a.set(state, {
|
|
71
|
+
onRemove: props.onRemove
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
gridProps: (0, $jLhmn$reactariautils.mergeProps)(gridProps, domProps, {
|
|
75
|
+
role: state.collection.size ? 'grid' : null,
|
|
76
|
+
'aria-atomic': false,
|
|
77
|
+
'aria-relevant': 'additions',
|
|
78
|
+
'aria-live': isFocusWithin ? 'polite' : 'off',
|
|
79
|
+
...focusWithinProps,
|
|
80
|
+
...fieldProps
|
|
81
|
+
}),
|
|
82
|
+
labelProps: labelProps,
|
|
83
|
+
descriptionProps: descriptionProps,
|
|
84
|
+
errorMessageProps: errorMessageProps
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
//# sourceMappingURL=useTagGroup.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AA4CM,MAAM,4CAAW,IAAI;AASrB,SAAS,0CAAe,KAA6B,EAAE,KAAmB,EAAE,GAA2B;IAC5G,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,8BAAQ;IAC1B,IAAI,mBAAmB,MAAM,gBAAgB,IAAI,IAAI,CAAA,GAAA,8CAAmB,EAAE;QACxE,YAAY,MAAM,UAAU;aAC5B;QACA,aAAa;mBACb;QACA,cAAc,MAAM,YAAY;QAChC,kBAAkB,MAAM,gBAAgB,CAAC,gBAAgB;IAC3D;IACA,IAAI,cAAC,UAAU,cAAE,UAAU,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,CAAA,GAAA,8BAAO,EAAE;QAC3E,GAAG,KAAK;QACR,kBAAkB;IACpB;IACA,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,oCAAU,EAAE;QAC5B,GAAG,KAAK;QACR,GAAG,UAAU;0BACb;QACA,iBAAiB;QACjB,cAAc;IAChB,GAAG,OAAO;IAEV,IAAI,CAAC,eAAe,eAAe,GAAG,CAAA,GAAA,qBAAO,EAAE;IAC/C,IAAI,oBAAC,gBAAgB,EAAC,GAAG,CAAA,GAAA,2CAAa,EAAE;QACtC,qBAAqB;IACvB;IACA,IAAI,WAAW,CAAA,GAAA,oCAAa,EAAE;IAE9B,mDAAmD;IACnD,IAAI,YAAY,CAAA,GAAA,mBAAK,EAAE,MAAM,UAAU,CAAC,IAAI;IAC5C,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,IAAI,OAAO,IAAI,UAAU,OAAO,GAAG,KAAK,MAAM,UAAU,CAAC,IAAI,KAAK,KAAK,eACzE,IAAI,OAAO,CAAC,KAAK;QAEnB,UAAU,OAAO,GAAG,MAAM,UAAU,CAAC,IAAI;IAC3C,GAAG;QAAC,MAAM,UAAU,CAAC,IAAI;QAAE;QAAe;KAAI;IAE9C,0CAAS,GAAG,CAAC,OAAO;QAAC,UAAU,MAAM,QAAQ;IAAA;IAE7C,OAAO;QACL,WAAW,CAAA,GAAA,gCAAS,EAAE,WAAW,UAAU;YACzC,MAAM,MAAM,UAAU,CAAC,IAAI,GAAG,SAAS;YACvC,eAAe;YACf,iBAAiB;YACjB,aAAa,gBAAgB,WAAW;YACxC,GAAG,gBAAgB;YACnB,GAAG,UAAU;QACf;oBACA;0BACA;2BACA;IACF;AACF","sources":["packages/@react-aria/tag/src/useTagGroup.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 {AriaLabelingProps, CollectionBase, DOMAttributes, DOMProps, HelpTextProps, Key, KeyboardDelegate, LabelableProps, MultipleSelection, SelectionBehavior} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {ListKeyboardDelegate} from '@react-aria/selection';\nimport type {ListState} from '@react-stately/list';\nimport {ReactNode, RefObject, useEffect, useRef, useState} from 'react';\nimport {useField} from '@react-aria/label';\nimport {useFocusWithin} from '@react-aria/interactions';\nimport {useGridList} from '@react-aria/gridlist';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface TagGroupAria {\n /** Props for the tag grouping element. */\n gridProps: DOMAttributes,\n /** Props for the tag group's visible label (if any). */\n labelProps: DOMAttributes,\n /** Props for the tag group description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the tag group error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\nexport interface AriaTagGroupProps<T> extends CollectionBase<T>, MultipleSelection, DOMProps, LabelableProps, AriaLabelingProps, Omit<HelpTextProps, 'errorMessage'> {\n /** How multiple selection should behave in the collection. */\n selectionBehavior?: SelectionBehavior,\n /** Handler that is called when a user deletes a tag. */\n onRemove?: (keys: Set<Key>) => void,\n /** An error message for the field. */\n errorMessage?: ReactNode\n}\n\nexport interface AriaTagGroupOptions<T> extends Omit<AriaTagGroupProps<T>, 'children'> {\n /**\n * An optional keyboard delegate to handle arrow key navigation,\n * to override the default.\n */\n keyboardDelegate?: KeyboardDelegate\n}\n\ninterface HookData {\n onRemove?: (keys: Set<Key>) => void\n}\n\nexport const hookData = new WeakMap<ListState<any>, HookData>();\n\n/**\n * Provides the behavior and accessibility implementation for a tag group component.\n * A tag group is a focusable list of labels, categories, keywords, filters, or other items, with support for keyboard navigation, selection, and removal.\n * @param props - Props to be applied to the tag group.\n * @param state - State for the tag group, as returned by `useListState`.\n * @param ref - A ref to a DOM element for the tag group.\n */\nexport function useTagGroup<T>(props: AriaTagGroupOptions<T>, state: ListState<T>, ref: RefObject<HTMLElement>): TagGroupAria {\n let {direction} = useLocale();\n let keyboardDelegate = props.keyboardDelegate || new ListKeyboardDelegate({\n collection: state.collection,\n ref,\n orientation: 'horizontal',\n direction,\n disabledKeys: state.disabledKeys,\n disabledBehavior: state.selectionManager.disabledBehavior\n });\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n labelElementType: 'span'\n });\n let {gridProps} = useGridList({\n ...props,\n ...fieldProps,\n keyboardDelegate,\n shouldFocusWrap: true,\n linkBehavior: 'override'\n }, state, ref);\n\n let [isFocusWithin, setFocusWithin] = useState(false);\n let {focusWithinProps} = useFocusWithin({\n onFocusWithinChange: setFocusWithin\n });\n let domProps = filterDOMProps(props);\n\n // If the last tag is removed, focus the container.\n let prevCount = useRef(state.collection.size);\n useEffect(() => {\n if (ref.current && prevCount.current > 0 && state.collection.size === 0 && isFocusWithin) {\n ref.current.focus();\n }\n prevCount.current = state.collection.size;\n }, [state.collection.size, isFocusWithin, ref]);\n\n hookData.set(state, {onRemove: props.onRemove});\n\n return {\n gridProps: mergeProps(gridProps, domProps, {\n role: state.collection.size ? 'grid' : null,\n 'aria-atomic': false,\n 'aria-relevant': 'additions',\n 'aria-live': isFocusWithin ? 'polite' : 'off',\n ...focusWithinProps,\n ...fieldProps\n }),\n labelProps,\n descriptionProps,\n errorMessageProps\n };\n}\n"],"names":[],"version":3,"file":"useTagGroup.main.js.map"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {filterDOMProps as $eUtJD$filterDOMProps, mergeProps as $eUtJD$mergeProps} from "@react-aria/utils";
|
|
2
|
+
import {ListKeyboardDelegate as $eUtJD$ListKeyboardDelegate} from "@react-aria/selection";
|
|
3
|
+
import {useState as $eUtJD$useState, useRef as $eUtJD$useRef, useEffect as $eUtJD$useEffect} from "react";
|
|
4
|
+
import {useField as $eUtJD$useField} from "@react-aria/label";
|
|
5
|
+
import {useFocusWithin as $eUtJD$useFocusWithin} from "@react-aria/interactions";
|
|
6
|
+
import {useGridList as $eUtJD$useGridList} from "@react-aria/gridlist";
|
|
7
|
+
import {useLocale as $eUtJD$useLocale} from "@react-aria/i18n";
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
11
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
13
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
16
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
17
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
18
|
+
* governing permissions and limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const $d7323bca8d074eeb$export$653eddfc964b0f8a = new WeakMap();
|
|
27
|
+
function $d7323bca8d074eeb$export$4f8b5cda58b7e8ff(props, state, ref) {
|
|
28
|
+
let { direction: direction } = (0, $eUtJD$useLocale)();
|
|
29
|
+
let keyboardDelegate = props.keyboardDelegate || new (0, $eUtJD$ListKeyboardDelegate)({
|
|
30
|
+
collection: state.collection,
|
|
31
|
+
ref: ref,
|
|
32
|
+
orientation: 'horizontal',
|
|
33
|
+
direction: direction,
|
|
34
|
+
disabledKeys: state.disabledKeys,
|
|
35
|
+
disabledBehavior: state.selectionManager.disabledBehavior
|
|
36
|
+
});
|
|
37
|
+
let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $eUtJD$useField)({
|
|
38
|
+
...props,
|
|
39
|
+
labelElementType: 'span'
|
|
40
|
+
});
|
|
41
|
+
let { gridProps: gridProps } = (0, $eUtJD$useGridList)({
|
|
42
|
+
...props,
|
|
43
|
+
...fieldProps,
|
|
44
|
+
keyboardDelegate: keyboardDelegate,
|
|
45
|
+
shouldFocusWrap: true,
|
|
46
|
+
linkBehavior: 'override'
|
|
47
|
+
}, state, ref);
|
|
48
|
+
let [isFocusWithin, setFocusWithin] = (0, $eUtJD$useState)(false);
|
|
49
|
+
let { focusWithinProps: focusWithinProps } = (0, $eUtJD$useFocusWithin)({
|
|
50
|
+
onFocusWithinChange: setFocusWithin
|
|
51
|
+
});
|
|
52
|
+
let domProps = (0, $eUtJD$filterDOMProps)(props);
|
|
53
|
+
// If the last tag is removed, focus the container.
|
|
54
|
+
let prevCount = (0, $eUtJD$useRef)(state.collection.size);
|
|
55
|
+
(0, $eUtJD$useEffect)(()=>{
|
|
56
|
+
if (ref.current && prevCount.current > 0 && state.collection.size === 0 && isFocusWithin) ref.current.focus();
|
|
57
|
+
prevCount.current = state.collection.size;
|
|
58
|
+
}, [
|
|
59
|
+
state.collection.size,
|
|
60
|
+
isFocusWithin,
|
|
61
|
+
ref
|
|
62
|
+
]);
|
|
63
|
+
$d7323bca8d074eeb$export$653eddfc964b0f8a.set(state, {
|
|
64
|
+
onRemove: props.onRemove
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
gridProps: (0, $eUtJD$mergeProps)(gridProps, domProps, {
|
|
68
|
+
role: state.collection.size ? 'grid' : null,
|
|
69
|
+
'aria-atomic': false,
|
|
70
|
+
'aria-relevant': 'additions',
|
|
71
|
+
'aria-live': isFocusWithin ? 'polite' : 'off',
|
|
72
|
+
...focusWithinProps,
|
|
73
|
+
...fieldProps
|
|
74
|
+
}),
|
|
75
|
+
labelProps: labelProps,
|
|
76
|
+
descriptionProps: descriptionProps,
|
|
77
|
+
errorMessageProps: errorMessageProps
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
export {$d7323bca8d074eeb$export$653eddfc964b0f8a as hookData, $d7323bca8d074eeb$export$4f8b5cda58b7e8ff as useTagGroup};
|
|
83
|
+
//# sourceMappingURL=useTagGroup.module.js.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {filterDOMProps as $eUtJD$filterDOMProps, mergeProps as $eUtJD$mergeProps} from "@react-aria/utils";
|
|
2
|
+
import {ListKeyboardDelegate as $eUtJD$ListKeyboardDelegate} from "@react-aria/selection";
|
|
3
|
+
import {useState as $eUtJD$useState, useRef as $eUtJD$useRef, useEffect as $eUtJD$useEffect} from "react";
|
|
4
|
+
import {useField as $eUtJD$useField} from "@react-aria/label";
|
|
5
|
+
import {useFocusWithin as $eUtJD$useFocusWithin} from "@react-aria/interactions";
|
|
6
|
+
import {useGridList as $eUtJD$useGridList} from "@react-aria/gridlist";
|
|
7
|
+
import {useLocale as $eUtJD$useLocale} from "@react-aria/i18n";
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
11
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
12
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
13
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
*
|
|
15
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
16
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
17
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
18
|
+
* governing permissions and limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const $d7323bca8d074eeb$export$653eddfc964b0f8a = new WeakMap();
|
|
27
|
+
function $d7323bca8d074eeb$export$4f8b5cda58b7e8ff(props, state, ref) {
|
|
28
|
+
let { direction: direction } = (0, $eUtJD$useLocale)();
|
|
29
|
+
let keyboardDelegate = props.keyboardDelegate || new (0, $eUtJD$ListKeyboardDelegate)({
|
|
30
|
+
collection: state.collection,
|
|
31
|
+
ref: ref,
|
|
32
|
+
orientation: 'horizontal',
|
|
33
|
+
direction: direction,
|
|
34
|
+
disabledKeys: state.disabledKeys,
|
|
35
|
+
disabledBehavior: state.selectionManager.disabledBehavior
|
|
36
|
+
});
|
|
37
|
+
let { labelProps: labelProps, fieldProps: fieldProps, descriptionProps: descriptionProps, errorMessageProps: errorMessageProps } = (0, $eUtJD$useField)({
|
|
38
|
+
...props,
|
|
39
|
+
labelElementType: 'span'
|
|
40
|
+
});
|
|
41
|
+
let { gridProps: gridProps } = (0, $eUtJD$useGridList)({
|
|
42
|
+
...props,
|
|
43
|
+
...fieldProps,
|
|
44
|
+
keyboardDelegate: keyboardDelegate,
|
|
45
|
+
shouldFocusWrap: true,
|
|
46
|
+
linkBehavior: 'override'
|
|
47
|
+
}, state, ref);
|
|
48
|
+
let [isFocusWithin, setFocusWithin] = (0, $eUtJD$useState)(false);
|
|
49
|
+
let { focusWithinProps: focusWithinProps } = (0, $eUtJD$useFocusWithin)({
|
|
50
|
+
onFocusWithinChange: setFocusWithin
|
|
51
|
+
});
|
|
52
|
+
let domProps = (0, $eUtJD$filterDOMProps)(props);
|
|
53
|
+
// If the last tag is removed, focus the container.
|
|
54
|
+
let prevCount = (0, $eUtJD$useRef)(state.collection.size);
|
|
55
|
+
(0, $eUtJD$useEffect)(()=>{
|
|
56
|
+
if (ref.current && prevCount.current > 0 && state.collection.size === 0 && isFocusWithin) ref.current.focus();
|
|
57
|
+
prevCount.current = state.collection.size;
|
|
58
|
+
}, [
|
|
59
|
+
state.collection.size,
|
|
60
|
+
isFocusWithin,
|
|
61
|
+
ref
|
|
62
|
+
]);
|
|
63
|
+
$d7323bca8d074eeb$export$653eddfc964b0f8a.set(state, {
|
|
64
|
+
onRemove: props.onRemove
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
gridProps: (0, $eUtJD$mergeProps)(gridProps, domProps, {
|
|
68
|
+
role: state.collection.size ? 'grid' : null,
|
|
69
|
+
'aria-atomic': false,
|
|
70
|
+
'aria-relevant': 'additions',
|
|
71
|
+
'aria-live': isFocusWithin ? 'polite' : 'off',
|
|
72
|
+
...focusWithinProps,
|
|
73
|
+
...fieldProps
|
|
74
|
+
}),
|
|
75
|
+
labelProps: labelProps,
|
|
76
|
+
descriptionProps: descriptionProps,
|
|
77
|
+
errorMessageProps: errorMessageProps
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
export {$d7323bca8d074eeb$export$653eddfc964b0f8a as hookData, $d7323bca8d074eeb$export$4f8b5cda58b7e8ff as useTagGroup};
|
|
83
|
+
//# sourceMappingURL=useTagGroup.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;;AA4CM,MAAM,4CAAW,IAAI;AASrB,SAAS,0CAAe,KAA6B,EAAE,KAAmB,EAAE,GAA2B;IAC5G,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAC1B,IAAI,mBAAmB,MAAM,gBAAgB,IAAI,IAAI,CAAA,GAAA,2BAAmB,EAAE;QACxE,YAAY,MAAM,UAAU;aAC5B;QACA,aAAa;mBACb;QACA,cAAc,MAAM,YAAY;QAChC,kBAAkB,MAAM,gBAAgB,CAAC,gBAAgB;IAC3D;IACA,IAAI,cAAC,UAAU,cAAE,UAAU,oBAAE,gBAAgB,qBAAE,iBAAiB,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;QAC3E,GAAG,KAAK;QACR,kBAAkB;IACpB;IACA,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,kBAAU,EAAE;QAC5B,GAAG,KAAK;QACR,GAAG,UAAU;0BACb;QACA,iBAAiB;QACjB,cAAc;IAChB,GAAG,OAAO;IAEV,IAAI,CAAC,eAAe,eAAe,GAAG,CAAA,GAAA,eAAO,EAAE;IAC/C,IAAI,oBAAC,gBAAgB,EAAC,GAAG,CAAA,GAAA,qBAAa,EAAE;QACtC,qBAAqB;IACvB;IACA,IAAI,WAAW,CAAA,GAAA,qBAAa,EAAE;IAE9B,mDAAmD;IACnD,IAAI,YAAY,CAAA,GAAA,aAAK,EAAE,MAAM,UAAU,CAAC,IAAI;IAC5C,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,IAAI,OAAO,IAAI,UAAU,OAAO,GAAG,KAAK,MAAM,UAAU,CAAC,IAAI,KAAK,KAAK,eACzE,IAAI,OAAO,CAAC,KAAK;QAEnB,UAAU,OAAO,GAAG,MAAM,UAAU,CAAC,IAAI;IAC3C,GAAG;QAAC,MAAM,UAAU,CAAC,IAAI;QAAE;QAAe;KAAI;IAE9C,0CAAS,GAAG,CAAC,OAAO;QAAC,UAAU,MAAM,QAAQ;IAAA;IAE7C,OAAO;QACL,WAAW,CAAA,GAAA,iBAAS,EAAE,WAAW,UAAU;YACzC,MAAM,MAAM,UAAU,CAAC,IAAI,GAAG,SAAS;YACvC,eAAe;YACf,iBAAiB;YACjB,aAAa,gBAAgB,WAAW;YACxC,GAAG,gBAAgB;YACnB,GAAG,UAAU;QACf;oBACA;0BACA;2BACA;IACF;AACF","sources":["packages/@react-aria/tag/src/useTagGroup.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 {AriaLabelingProps, CollectionBase, DOMAttributes, DOMProps, HelpTextProps, Key, KeyboardDelegate, LabelableProps, MultipleSelection, SelectionBehavior} from '@react-types/shared';\nimport {filterDOMProps, mergeProps} from '@react-aria/utils';\nimport {ListKeyboardDelegate} from '@react-aria/selection';\nimport type {ListState} from '@react-stately/list';\nimport {ReactNode, RefObject, useEffect, useRef, useState} from 'react';\nimport {useField} from '@react-aria/label';\nimport {useFocusWithin} from '@react-aria/interactions';\nimport {useGridList} from '@react-aria/gridlist';\nimport {useLocale} from '@react-aria/i18n';\n\nexport interface TagGroupAria {\n /** Props for the tag grouping element. */\n gridProps: DOMAttributes,\n /** Props for the tag group's visible label (if any). */\n labelProps: DOMAttributes,\n /** Props for the tag group description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the tag group error message element, if any. */\n errorMessageProps: DOMAttributes\n}\n\nexport interface AriaTagGroupProps<T> extends CollectionBase<T>, MultipleSelection, DOMProps, LabelableProps, AriaLabelingProps, Omit<HelpTextProps, 'errorMessage'> {\n /** How multiple selection should behave in the collection. */\n selectionBehavior?: SelectionBehavior,\n /** Handler that is called when a user deletes a tag. */\n onRemove?: (keys: Set<Key>) => void,\n /** An error message for the field. */\n errorMessage?: ReactNode\n}\n\nexport interface AriaTagGroupOptions<T> extends Omit<AriaTagGroupProps<T>, 'children'> {\n /**\n * An optional keyboard delegate to handle arrow key navigation,\n * to override the default.\n */\n keyboardDelegate?: KeyboardDelegate\n}\n\ninterface HookData {\n onRemove?: (keys: Set<Key>) => void\n}\n\nexport const hookData = new WeakMap<ListState<any>, HookData>();\n\n/**\n * Provides the behavior and accessibility implementation for a tag group component.\n * A tag group is a focusable list of labels, categories, keywords, filters, or other items, with support for keyboard navigation, selection, and removal.\n * @param props - Props to be applied to the tag group.\n * @param state - State for the tag group, as returned by `useListState`.\n * @param ref - A ref to a DOM element for the tag group.\n */\nexport function useTagGroup<T>(props: AriaTagGroupOptions<T>, state: ListState<T>, ref: RefObject<HTMLElement>): TagGroupAria {\n let {direction} = useLocale();\n let keyboardDelegate = props.keyboardDelegate || new ListKeyboardDelegate({\n collection: state.collection,\n ref,\n orientation: 'horizontal',\n direction,\n disabledKeys: state.disabledKeys,\n disabledBehavior: state.selectionManager.disabledBehavior\n });\n let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({\n ...props,\n labelElementType: 'span'\n });\n let {gridProps} = useGridList({\n ...props,\n ...fieldProps,\n keyboardDelegate,\n shouldFocusWrap: true,\n linkBehavior: 'override'\n }, state, ref);\n\n let [isFocusWithin, setFocusWithin] = useState(false);\n let {focusWithinProps} = useFocusWithin({\n onFocusWithinChange: setFocusWithin\n });\n let domProps = filterDOMProps(props);\n\n // If the last tag is removed, focus the container.\n let prevCount = useRef(state.collection.size);\n useEffect(() => {\n if (ref.current && prevCount.current > 0 && state.collection.size === 0 && isFocusWithin) {\n ref.current.focus();\n }\n prevCount.current = state.collection.size;\n }, [state.collection.size, isFocusWithin, ref]);\n\n hookData.set(state, {onRemove: props.onRemove});\n\n return {\n gridProps: mergeProps(gridProps, domProps, {\n role: state.collection.size ? 'grid' : null,\n 'aria-atomic': false,\n 'aria-relevant': 'additions',\n 'aria-live': isFocusWithin ? 'polite' : 'off',\n ...focusWithinProps,\n ...fieldProps\n }),\n labelProps,\n descriptionProps,\n errorMessageProps\n };\n}\n"],"names":[],"version":3,"file":"useTagGroup.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/tag",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-aria/gridlist": "^3.
|
|
26
|
-
"@react-aria/i18n": "^3.
|
|
27
|
-
"@react-aria/interactions": "^3.21.
|
|
28
|
-
"@react-aria/label": "^3.7.
|
|
29
|
-
"@react-aria/selection": "^3.
|
|
30
|
-
"@react-aria/utils": "^3.
|
|
31
|
-
"@react-stately/list": "^3.10.
|
|
32
|
-
"@react-types/button": "^3.9.
|
|
33
|
-
"@react-types/shared": "^3.
|
|
25
|
+
"@react-aria/gridlist": "^3.8.1",
|
|
26
|
+
"@react-aria/i18n": "^3.11.1",
|
|
27
|
+
"@react-aria/interactions": "^3.21.3",
|
|
28
|
+
"@react-aria/label": "^3.7.8",
|
|
29
|
+
"@react-aria/selection": "^3.18.1",
|
|
30
|
+
"@react-aria/utils": "^3.24.1",
|
|
31
|
+
"@react-stately/list": "^3.10.5",
|
|
32
|
+
"@react-types/button": "^3.9.4",
|
|
33
|
+
"@react-types/shared": "^3.23.1",
|
|
34
34
|
"@swc/helpers": "^0.5.0"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "b77d7d594dff4dcfb5359bffbcfd18142b146433"
|
|
44
44
|
}
|
package/src/useTagGroup.ts
CHANGED
|
@@ -68,7 +68,8 @@ export function useTagGroup<T>(props: AriaTagGroupOptions<T>, state: ListState<T
|
|
|
68
68
|
ref,
|
|
69
69
|
orientation: 'horizontal',
|
|
70
70
|
direction,
|
|
71
|
-
disabledKeys: state.disabledKeys
|
|
71
|
+
disabledKeys: state.disabledKeys,
|
|
72
|
+
disabledBehavior: state.selectionManager.disabledBehavior
|
|
72
73
|
});
|
|
73
74
|
let {labelProps, fieldProps, descriptionProps, errorMessageProps} = useField({
|
|
74
75
|
...props,
|