@react-aria/actiongroup 3.6.5-nightly.4274 → 3.7.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 CHANGED
@@ -35,13 +35,12 @@ const $304ac34015d4535d$var$BUTTON_GROUP_ROLES = {
35
35
  function $304ac34015d4535d$export$f4bf8d43c16de704(props, state, ref) {
36
36
  let { isDisabled: isDisabled, orientation: orientation = "horizontal" } = props;
37
37
  let [isInToolbar, setInToolbar] = (0, $1oG4F$useState)(false);
38
- // should be safe because re-calling set state with the same value it already has is a no-op
39
- // this will allow us to react should a parent re-render and change its role though
40
- // eslint-disable-next-line react-hooks/exhaustive-deps
41
38
  (0, $1oG4F$useLayoutEffect)(()=>{
42
39
  var _ref_current_parentElement;
43
40
  setInToolbar(!!(ref.current && ((_ref_current_parentElement = ref.current.parentElement) === null || _ref_current_parentElement === void 0 ? void 0 : _ref_current_parentElement.closest('[role="toolbar"]'))));
44
- });
41
+ }, [
42
+ ref
43
+ ]);
45
44
  let allKeys = [
46
45
  ...state.collection.getKeys()
47
46
  ];
package/dist/main.js CHANGED
@@ -42,13 +42,12 @@ const $ceb684449a137553$var$BUTTON_GROUP_ROLES = {
42
42
  function $ceb684449a137553$export$f4bf8d43c16de704(props, state, ref) {
43
43
  let { isDisabled: isDisabled, orientation: orientation = "horizontal" } = props;
44
44
  let [isInToolbar, setInToolbar] = (0, $hjKwo$react.useState)(false);
45
- // should be safe because re-calling set state with the same value it already has is a no-op
46
- // this will allow us to react should a parent re-render and change its role though
47
- // eslint-disable-next-line react-hooks/exhaustive-deps
48
45
  (0, $hjKwo$reactariautils.useLayoutEffect)(()=>{
49
46
  var _ref_current_parentElement;
50
47
  setInToolbar(!!(ref.current && ((_ref_current_parentElement = ref.current.parentElement) === null || _ref_current_parentElement === void 0 ? void 0 : _ref_current_parentElement.closest('[role="toolbar"]'))));
51
- });
48
+ }, [
49
+ ref
50
+ ]);
52
51
  let allKeys = [
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,GAAG;YAChD;YACA;gBACE,MAAM,gBAAgB,CAAC,MAAM,CAAC,MAAM,GAAG;YACzC;QACF;IACF;AACF;","sources":["packages/@react-aria/actiongroup/src/index.ts","packages/@react-aria/actiongroup/src/useActionGroup.ts","packages/@react-aria/actiongroup/src/useActionGroupItem.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 */\nexport type {ActionGroupAria} from './useActionGroup';\nexport {useActionGroup} from './useActionGroup';\nexport {useActionGroupItem} from './useActionGroupItem';\nexport type {AriaActionGroupProps} from '@react-types/actiongroup';\nexport type {ActionGroupItemAria, AriaActionGroupItemProps} from './useActionGroupItem';\n","/*\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 {AriaActionGroupProps} from '@react-types/actiongroup';\nimport {createFocusManager} from '@react-aria/focus';\nimport {DOMAttributes, FocusableElement, Orientation} from '@react-types/shared';\nimport {filterDOMProps, useLayoutEffect} from '@react-aria/utils';\nimport {ListState} from '@react-stately/list';\nimport {RefObject, useState} from 'react';\nimport {useLocale} from '@react-aria/i18n';\n\nconst BUTTON_GROUP_ROLES = {\n 'none': 'toolbar',\n 'single': 'radiogroup',\n 'multiple': 'toolbar'\n};\n\nexport interface ActionGroupAria {\n actionGroupProps: DOMAttributes\n}\n\nexport function useActionGroup<T>(props: AriaActionGroupProps<T>, state: ListState<T>, ref: RefObject<FocusableElement>): ActionGroupAria {\n let {\n isDisabled,\n orientation = 'horizontal' as Orientation\n } = props;\n\n let [isInToolbar, setInToolbar] = useState(false);\n // should be safe because re-calling set state with the same value it already has is a no-op\n // this will allow us to react should a parent re-render and change its role though\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(() => {\n setInToolbar(!!(ref.current && ref.current.parentElement?.closest('[role=\"toolbar\"]')));\n });\n\n let allKeys = [...state.collection.getKeys()];\n if (!allKeys.some(key => !state.disabledKeys.has(key))) {\n isDisabled = true;\n }\n\n let {direction} = useLocale();\n let focusManager = createFocusManager(ref);\n let flipDirection = direction === 'rtl' && orientation === 'horizontal';\n let onKeyDown = (e) => {\n if (!e.currentTarget.contains(e.target)) {\n return;\n }\n\n switch (e.key) {\n case 'ArrowRight':\n case 'ArrowDown':\n e.preventDefault();\n e.stopPropagation();\n if (e.key === 'ArrowRight' && flipDirection) {\n focusManager.focusPrevious({wrap: true});\n } else {\n focusManager.focusNext({wrap: true});\n }\n break;\n case 'ArrowLeft':\n case 'ArrowUp':\n e.preventDefault();\n e.stopPropagation();\n if (e.key === 'ArrowLeft' && flipDirection) {\n focusManager.focusNext({wrap: true});\n } else {\n focusManager.focusPrevious({wrap: true});\n }\n break;\n }\n };\n\n let role: string | undefined = BUTTON_GROUP_ROLES[state.selectionManager.selectionMode];\n if (isInToolbar && role === 'toolbar') {\n role = 'group';\n }\n return {\n actionGroupProps: {\n ...filterDOMProps(props, {labelable: true}),\n role,\n 'aria-orientation': role === 'toolbar' ? orientation : undefined,\n 'aria-disabled': isDisabled,\n onKeyDown\n }\n };\n}\n","/*\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, Key} from '@react-types/shared';\nimport {ListState} from '@react-stately/list';\nimport {mergeProps, useEffectEvent} from '@react-aria/utils';\nimport {PressProps} from '@react-aria/interactions';\nimport {RefObject, useEffect} from 'react';\n\nexport interface AriaActionGroupItemProps {\n key: Key\n}\n\nexport interface ActionGroupItemAria {\n buttonProps: DOMAttributes & PressProps\n}\n\nconst BUTTON_ROLES = {\n 'none': undefined,\n 'single': 'radio',\n 'multiple': 'checkbox'\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function useActionGroupItem<T>(props: AriaActionGroupItemProps, state: ListState<T>, ref?: RefObject<FocusableElement>): ActionGroupItemAria {\n let selectionMode = state.selectionManager.selectionMode;\n let buttonProps = {\n role: BUTTON_ROLES[selectionMode]\n };\n\n if (selectionMode !== 'none') {\n let isSelected = state.selectionManager.isSelected(props.key);\n buttonProps['aria-checked'] = isSelected;\n }\n\n let isFocused = props.key === state.selectionManager.focusedKey;\n let onRemovedWithFocus = useEffectEvent(() => {\n if (isFocused) {\n state.selectionManager.setFocusedKey(null);\n }\n });\n\n // If the focused item is removed from the DOM, reset the focused key to null.\n useEffect(() => {\n return () => {\n onRemovedWithFocus();\n };\n }, [onRemovedWithFocus]);\n\n return {\n buttonProps: mergeProps(buttonProps, {\n tabIndex: isFocused || state.selectionManager.focusedKey == null ? 0 : -1,\n onFocus() {\n state.selectionManager.setFocusedKey(props.key);\n },\n onPress() {\n state.selectionManager.select(props.key);\n }\n })\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;;AAUD,MAAM,2CAAqB;IACzB,QAAQ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,gBAAgB,CAAC,aAAa,CAAC;IACvF,IAAI,eAAe,SAAS,WAC1B,OAAO;IAET,OAAO;QACL,kBAAkB;YAChB,GAAG,CAAA,GAAA,oCAAa,EAAE,OAAO;gBAAC,WAAW;YAAI,EAAE;kBAC3C;YACA,oBAAoB,SAAS,YAAY,cAAc;YACvD,iBAAiB;uBACjB;QACF;IACF;AACF;;CDjFC;AEVD;;;;;;;;;;CAUC;;AAgBD,MAAM,qCAAe;IACnB,QAAQ;IACR,UAAU;IACV,YAAY;AACd;AAGO,SAAS,0CAAsB,KAA+B,EAAE,KAAmB,EAAE,GAAiC;IAC3H,IAAI,gBAAgB,MAAM,gBAAgB,CAAC,aAAa;IACxD,IAAI,cAAc;QAChB,MAAM,kCAAY,CAAC,cAAc;IACnC;IAEA,IAAI,kBAAkB,QAAQ;QAC5B,IAAI,aAAa,MAAM,gBAAgB,CAAC,UAAU,CAAC,MAAM,GAAG;QAC5D,WAAW,CAAC,eAAe,GAAG;IAChC;IAEA,IAAI,YAAY,MAAM,GAAG,KAAK,MAAM,gBAAgB,CAAC,UAAU;IAC/D,IAAI,qBAAqB,CAAA,GAAA,oCAAa,EAAE;QACtC,IAAI,WACF,MAAM,gBAAgB,CAAC,aAAa,CAAC;IAEzC;IAEA,8EAA8E;IAC9E,CAAA,GAAA,sBAAQ,EAAE;QACR,OAAO;YACL;QACF;IACF,GAAG;QAAC;KAAmB;IAEvB,OAAO;QACL,aAAa,CAAA,GAAA,gCAAS,EAAE,aAAa;YACnC,UAAU,aAAa,MAAM,gBAAgB,CAAC,UAAU,IAAI,OAAO,IAAI;YACvE;gBACE,MAAM,gBAAgB,CAAC,aAAa,CAAC,MAAM,GAAG;YAChD;YACA;gBACE,MAAM,gBAAgB,CAAC,MAAM,CAAC,MAAM,GAAG;YACzC;QACF;IACF;AACF;","sources":["packages/@react-aria/actiongroup/src/index.ts","packages/@react-aria/actiongroup/src/useActionGroup.ts","packages/@react-aria/actiongroup/src/useActionGroupItem.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 */\nexport type {ActionGroupAria} from './useActionGroup';\nexport {useActionGroup} from './useActionGroup';\nexport {useActionGroupItem} from './useActionGroupItem';\nexport type {AriaActionGroupProps} from '@react-types/actiongroup';\nexport type {ActionGroupItemAria, AriaActionGroupItemProps} from './useActionGroupItem';\n","/*\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 {AriaActionGroupProps} from '@react-types/actiongroup';\nimport {createFocusManager} from '@react-aria/focus';\nimport {DOMAttributes, FocusableElement, Orientation} from '@react-types/shared';\nimport {filterDOMProps, useLayoutEffect} from '@react-aria/utils';\nimport {ListState} from '@react-stately/list';\nimport {RefObject, useState} from 'react';\nimport {useLocale} from '@react-aria/i18n';\n\nconst BUTTON_GROUP_ROLES = {\n 'none': 'toolbar',\n 'single': 'radiogroup',\n 'multiple': 'toolbar'\n};\n\nexport interface ActionGroupAria {\n actionGroupProps: DOMAttributes\n}\n\nexport function useActionGroup<T>(props: AriaActionGroupProps<T>, state: ListState<T>, ref: RefObject<FocusableElement>): ActionGroupAria {\n let {\n isDisabled,\n orientation = 'horizontal' as Orientation\n } = props;\n\n let [isInToolbar, setInToolbar] = useState(false);\n useLayoutEffect(() => {\n setInToolbar(!!(ref.current && ref.current.parentElement?.closest('[role=\"toolbar\"]')));\n }, [ref]);\n\n let allKeys = [...state.collection.getKeys()];\n if (!allKeys.some(key => !state.disabledKeys.has(key))) {\n isDisabled = true;\n }\n\n let {direction} = useLocale();\n let focusManager = createFocusManager(ref);\n let flipDirection = direction === 'rtl' && orientation === 'horizontal';\n let onKeyDown = (e) => {\n if (!e.currentTarget.contains(e.target)) {\n return;\n }\n\n switch (e.key) {\n case 'ArrowRight':\n case 'ArrowDown':\n e.preventDefault();\n e.stopPropagation();\n if (e.key === 'ArrowRight' && flipDirection) {\n focusManager.focusPrevious({wrap: true});\n } else {\n focusManager.focusNext({wrap: true});\n }\n break;\n case 'ArrowLeft':\n case 'ArrowUp':\n e.preventDefault();\n e.stopPropagation();\n if (e.key === 'ArrowLeft' && flipDirection) {\n focusManager.focusNext({wrap: true});\n } else {\n focusManager.focusPrevious({wrap: true});\n }\n break;\n }\n };\n\n let role: string | undefined = BUTTON_GROUP_ROLES[state.selectionManager.selectionMode];\n if (isInToolbar && role === 'toolbar') {\n role = 'group';\n }\n return {\n actionGroupProps: {\n ...filterDOMProps(props, {labelable: true}),\n role,\n 'aria-orientation': role === 'toolbar' ? orientation : undefined,\n 'aria-disabled': isDisabled,\n onKeyDown\n }\n };\n}\n","/*\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, Key} from '@react-types/shared';\nimport {ListState} from '@react-stately/list';\nimport {mergeProps, useEffectEvent} from '@react-aria/utils';\nimport {PressProps} from '@react-aria/interactions';\nimport {RefObject, useEffect} from 'react';\n\nexport interface AriaActionGroupItemProps {\n key: Key\n}\n\nexport interface ActionGroupItemAria {\n buttonProps: DOMAttributes & PressProps\n}\n\nconst BUTTON_ROLES = {\n 'none': undefined,\n 'single': 'radio',\n 'multiple': 'checkbox'\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function useActionGroupItem<T>(props: AriaActionGroupItemProps, state: ListState<T>, ref?: RefObject<FocusableElement>): ActionGroupItemAria {\n let selectionMode = state.selectionManager.selectionMode;\n let buttonProps = {\n role: BUTTON_ROLES[selectionMode]\n };\n\n if (selectionMode !== 'none') {\n let isSelected = state.selectionManager.isSelected(props.key);\n buttonProps['aria-checked'] = isSelected;\n }\n\n let isFocused = props.key === state.selectionManager.focusedKey;\n let onRemovedWithFocus = useEffectEvent(() => {\n if (isFocused) {\n state.selectionManager.setFocusedKey(null);\n }\n });\n\n // If the focused item is removed from the DOM, reset the focused key to null.\n useEffect(() => {\n return () => {\n onRemovedWithFocus();\n };\n }, [onRemovedWithFocus]);\n\n return {\n buttonProps: mergeProps(buttonProps, {\n tabIndex: isFocused || state.selectionManager.focusedKey == null ? 0 : -1,\n onFocus() {\n state.selectionManager.setFocusedKey(props.key);\n },\n onPress() {\n state.selectionManager.select(props.key);\n }\n })\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -35,13 +35,12 @@ const $304ac34015d4535d$var$BUTTON_GROUP_ROLES = {
35
35
  function $304ac34015d4535d$export$f4bf8d43c16de704(props, state, ref) {
36
36
  let { isDisabled: isDisabled, orientation: orientation = "horizontal" } = props;
37
37
  let [isInToolbar, setInToolbar] = (0, $1oG4F$useState)(false);
38
- // should be safe because re-calling set state with the same value it already has is a no-op
39
- // this will allow us to react should a parent re-render and change its role though
40
- // eslint-disable-next-line react-hooks/exhaustive-deps
41
38
  (0, $1oG4F$useLayoutEffect)(()=>{
42
39
  var _ref_current_parentElement;
43
40
  setInToolbar(!!(ref.current && ((_ref_current_parentElement = ref.current.parentElement) === null || _ref_current_parentElement === void 0 ? void 0 : _ref_current_parentElement.closest('[role="toolbar"]'))));
44
- });
41
+ }, [
42
+ ref
43
+ ]);
45
44
  let allKeys = [
46
45
  ...state.collection.getKeys()
47
46
  ];
@@ -1 +1 @@
1
- {"mappings":";;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC;;;;AAUD,MAAM,2CAAqB;IACzB,QAAQ;IACR,UAAU;IACV,YAAY;AACd;AAMO,SAAS,0CAAkB,KAA8B,EAAE,KAAmB,EAAE,GAAgC;IACrH,IAAI,cACF,UAAU,eACV,cAAc,cACf,GAAG;IAEJ,IAAI,CAAC,aAAa,aAAa,GAAG,CAAA,GAAA,eAAO,EAAE;IAC3C,4FAA4F;IAC5F,mFAAmF;IACnF,uDAAuD;IACvD,CAAA,GAAA,sBAAc,EAAE;YACiB;QAA/B,aAAa,CAAC,CAAE,CAAA,IAAI,OAAO,MAAI,6BAAA,IAAI,OAAO,CAAC,aAAa,cAAzB,iDAAA,2BAA2B,OAAO,CAAC,oBAAkB;IACtF;IAEA,IAAI,UAAU;WAAI,MAAM,UAAU,CAAC,OAAO;KAAG;IAC7C,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAA,MAAO,CAAC,MAAM,YAAY,CAAC,GAAG,CAAC,OAC/C,aAAa;IAGf,IAAI,aAAC,SAAS,EAAC,GAAG,CAAA,GAAA,gBAAQ;IAC1B,IAAI,eAAe,CAAA,GAAA,yBAAiB,EAAE;IACtC,IAAI,gBAAgB,cAAc,SAAS,gBAAgB;IAC3D,IAAI,YAAY,CAAC;QACf,IAAI,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE,MAAM,GACpC;QAGF,OAAQ,EAAE,GAAG;YACX,KAAK;YACL,KAAK;gBACH,EAAE,cAAc;gBAChB,EAAE,eAAe;gBACjB,IAAI,EAAE,GAAG,KAAK,gBAAgB,eAC5B,aAAa,aAAa,CAAC;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S,EAAE,aAAa;YACnC,UAAU,aAAa,MAAM,gBAAgB,CAAC,UAAU,IAAI,OAAO,IAAI;YACvE;gBACE,MAAM,gBAAgB,CAAC,aAAa,CAAC,MAAM,GAAG;YAChD;YACA;gBACE,MAAM,gBAAgB,CAAC,MAAM,CAAC,MAAM,GAAG;YACzC;QACF;IACF;AACF;","sources":["packages/@react-aria/actiongroup/src/index.ts","packages/@react-aria/actiongroup/src/useActionGroup.ts","packages/@react-aria/actiongroup/src/useActionGroupItem.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 */\nexport type {ActionGroupAria} from './useActionGroup';\nexport {useActionGroup} from './useActionGroup';\nexport {useActionGroupItem} from './useActionGroupItem';\nexport type {AriaActionGroupProps} from '@react-types/actiongroup';\nexport type {ActionGroupItemAria, AriaActionGroupItemProps} from './useActionGroupItem';\n","/*\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 {AriaActionGroupProps} from '@react-types/actiongroup';\nimport {createFocusManager} from '@react-aria/focus';\nimport {DOMAttributes, FocusableElement, Orientation} from '@react-types/shared';\nimport {filterDOMProps, useLayoutEffect} from '@react-aria/utils';\nimport {ListState} from '@react-stately/list';\nimport {RefObject, useState} from 'react';\nimport {useLocale} from '@react-aria/i18n';\n\nconst BUTTON_GROUP_ROLES = {\n 'none': 'toolbar',\n 'single': 'radiogroup',\n 'multiple': 'toolbar'\n};\n\nexport interface ActionGroupAria {\n actionGroupProps: DOMAttributes\n}\n\nexport function useActionGroup<T>(props: AriaActionGroupProps<T>, state: ListState<T>, ref: RefObject<FocusableElement>): ActionGroupAria {\n let {\n isDisabled,\n orientation = 'horizontal' as Orientation\n } = props;\n\n let [isInToolbar, setInToolbar] = useState(false);\n // should be safe because re-calling set state with the same value it already has is a no-op\n // this will allow us to react should a parent re-render and change its role though\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useLayoutEffect(() => {\n setInToolbar(!!(ref.current && ref.current.parentElement?.closest('[role=\"toolbar\"]')));\n });\n\n let allKeys = [...state.collection.getKeys()];\n if (!allKeys.some(key => !state.disabledKeys.has(key))) {\n isDisabled = true;\n }\n\n let {direction} = useLocale();\n let focusManager = createFocusManager(ref);\n let flipDirection = direction === 'rtl' && orientation === 'horizontal';\n let onKeyDown = (e) => {\n if (!e.currentTarget.contains(e.target)) {\n return;\n }\n\n switch (e.key) {\n case 'ArrowRight':\n case 'ArrowDown':\n e.preventDefault();\n e.stopPropagation();\n if (e.key === 'ArrowRight' && flipDirection) {\n focusManager.focusPrevious({wrap: true});\n } else {\n focusManager.focusNext({wrap: true});\n }\n break;\n case 'ArrowLeft':\n case 'ArrowUp':\n e.preventDefault();\n e.stopPropagation();\n if (e.key === 'ArrowLeft' && flipDirection) {\n focusManager.focusNext({wrap: true});\n } else {\n focusManager.focusPrevious({wrap: true});\n }\n break;\n }\n };\n\n let role: string | undefined = BUTTON_GROUP_ROLES[state.selectionManager.selectionMode];\n if (isInToolbar && role === 'toolbar') {\n role = 'group';\n }\n return {\n actionGroupProps: {\n ...filterDOMProps(props, {labelable: true}),\n role,\n 'aria-orientation': role === 'toolbar' ? orientation : undefined,\n 'aria-disabled': isDisabled,\n onKeyDown\n }\n };\n}\n","/*\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, Key} from '@react-types/shared';\nimport {ListState} from '@react-stately/list';\nimport {mergeProps, useEffectEvent} from '@react-aria/utils';\nimport {PressProps} from '@react-aria/interactions';\nimport {RefObject, useEffect} from 'react';\n\nexport interface AriaActionGroupItemProps {\n key: Key\n}\n\nexport interface ActionGroupItemAria {\n buttonProps: DOMAttributes & PressProps\n}\n\nconst BUTTON_ROLES = {\n 'none': undefined,\n 'single': 'radio',\n 'multiple': 'checkbox'\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function useActionGroupItem<T>(props: AriaActionGroupItemProps, state: ListState<T>, ref?: RefObject<FocusableElement>): ActionGroupItemAria {\n let selectionMode = state.selectionManager.selectionMode;\n let buttonProps = {\n role: BUTTON_ROLES[selectionMode]\n };\n\n if (selectionMode !== 'none') {\n let isSelected = state.selectionManager.isSelected(props.key);\n buttonProps['aria-checked'] = isSelected;\n }\n\n let isFocused = props.key === state.selectionManager.focusedKey;\n let onRemovedWithFocus = useEffectEvent(() => {\n if (isFocused) {\n state.selectionManager.setFocusedKey(null);\n }\n });\n\n // If the focused item is removed from the DOM, reset the focused key to null.\n useEffect(() => {\n return () => {\n onRemovedWithFocus();\n };\n }, [onRemovedWithFocus]);\n\n return {\n buttonProps: mergeProps(buttonProps, {\n tabIndex: isFocused || state.selectionManager.focusedKey == null ? 0 : -1,\n onFocus() {\n state.selectionManager.setFocusedKey(props.key);\n },\n onPress() {\n state.selectionManager.select(props.key);\n }\n })\n };\n}\n"],"names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F;IACF;AACF;","sources":["packages/@react-aria/actiongroup/src/index.ts","packages/@react-aria/actiongroup/src/useActionGroup.ts","packages/@react-aria/actiongroup/src/useActionGroupItem.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 */\nexport type {ActionGroupAria} from './useActionGroup';\nexport {useActionGroup} from './useActionGroup';\nexport {useActionGroupItem} from './useActionGroupItem';\nexport type {AriaActionGroupProps} from '@react-types/actiongroup';\nexport type {ActionGroupItemAria, AriaActionGroupItemProps} from './useActionGroupItem';\n","/*\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 {AriaActionGroupProps} from '@react-types/actiongroup';\nimport {createFocusManager} from '@react-aria/focus';\nimport {DOMAttributes, FocusableElement, Orientation} from '@react-types/shared';\nimport {filterDOMProps, useLayoutEffect} from '@react-aria/utils';\nimport {ListState} from '@react-stately/list';\nimport {RefObject, useState} from 'react';\nimport {useLocale} from '@react-aria/i18n';\n\nconst BUTTON_GROUP_ROLES = {\n 'none': 'toolbar',\n 'single': 'radiogroup',\n 'multiple': 'toolbar'\n};\n\nexport interface ActionGroupAria {\n actionGroupProps: DOMAttributes\n}\n\nexport function useActionGroup<T>(props: AriaActionGroupProps<T>, state: ListState<T>, ref: RefObject<FocusableElement>): ActionGroupAria {\n let {\n isDisabled,\n orientation = 'horizontal' as Orientation\n } = props;\n\n let [isInToolbar, setInToolbar] = useState(false);\n useLayoutEffect(() => {\n setInToolbar(!!(ref.current && ref.current.parentElement?.closest('[role=\"toolbar\"]')));\n }, [ref]);\n\n let allKeys = [...state.collection.getKeys()];\n if (!allKeys.some(key => !state.disabledKeys.has(key))) {\n isDisabled = true;\n }\n\n let {direction} = useLocale();\n let focusManager = createFocusManager(ref);\n let flipDirection = direction === 'rtl' && orientation === 'horizontal';\n let onKeyDown = (e) => {\n if (!e.currentTarget.contains(e.target)) {\n return;\n }\n\n switch (e.key) {\n case 'ArrowRight':\n case 'ArrowDown':\n e.preventDefault();\n e.stopPropagation();\n if (e.key === 'ArrowRight' && flipDirection) {\n focusManager.focusPrevious({wrap: true});\n } else {\n focusManager.focusNext({wrap: true});\n }\n break;\n case 'ArrowLeft':\n case 'ArrowUp':\n e.preventDefault();\n e.stopPropagation();\n if (e.key === 'ArrowLeft' && flipDirection) {\n focusManager.focusNext({wrap: true});\n } else {\n focusManager.focusPrevious({wrap: true});\n }\n break;\n }\n };\n\n let role: string | undefined = BUTTON_GROUP_ROLES[state.selectionManager.selectionMode];\n if (isInToolbar && role === 'toolbar') {\n role = 'group';\n }\n return {\n actionGroupProps: {\n ...filterDOMProps(props, {labelable: true}),\n role,\n 'aria-orientation': role === 'toolbar' ? orientation : undefined,\n 'aria-disabled': isDisabled,\n onKeyDown\n }\n };\n}\n","/*\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, Key} from '@react-types/shared';\nimport {ListState} from '@react-stately/list';\nimport {mergeProps, useEffectEvent} from '@react-aria/utils';\nimport {PressProps} from '@react-aria/interactions';\nimport {RefObject, useEffect} from 'react';\n\nexport interface AriaActionGroupItemProps {\n key: Key\n}\n\nexport interface ActionGroupItemAria {\n buttonProps: DOMAttributes & PressProps\n}\n\nconst BUTTON_ROLES = {\n 'none': undefined,\n 'single': 'radio',\n 'multiple': 'checkbox'\n};\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function useActionGroupItem<T>(props: AriaActionGroupItemProps, state: ListState<T>, ref?: RefObject<FocusableElement>): ActionGroupItemAria {\n let selectionMode = state.selectionManager.selectionMode;\n let buttonProps = {\n role: BUTTON_ROLES[selectionMode]\n };\n\n if (selectionMode !== 'none') {\n let isSelected = state.selectionManager.isSelected(props.key);\n buttonProps['aria-checked'] = isSelected;\n }\n\n let isFocused = props.key === state.selectionManager.focusedKey;\n let onRemovedWithFocus = useEffectEvent(() => {\n if (isFocused) {\n state.selectionManager.setFocusedKey(null);\n }\n });\n\n // If the focused item is removed from the DOM, reset the focused key to null.\n useEffect(() => {\n return () => {\n onRemovedWithFocus();\n };\n }, [onRemovedWithFocus]);\n\n return {\n buttonProps: mergeProps(buttonProps, {\n tabIndex: isFocused || state.selectionManager.focusedKey == null ? 0 : -1,\n onFocus() {\n state.selectionManager.setFocusedKey(props.key);\n },\n onPress() {\n state.selectionManager.select(props.key);\n }\n })\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;;;AA0BA;IACE,gBAAgB,EAAE,aAAa,CAAA;CAChC;AAED,+BAA+B,CAAC,EAAE,KAAK,EAAE,qBAAqB,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,gBAAgB,CAAC,GAAG,eAAe,CAgExI;AC5ED;IACE,GAAG,EAAE,GAAG,CAAA;CACT;AAED;IACE,WAAW,EAAE,aAAa,GAAG,UAAU,CAAA;CACxC;AASD,mCAAmC,CAAC,EAAE,KAAK,EAAE,wBAAwB,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,UAAU,gBAAgB,CAAC,GAAG,mBAAmB,CAoClJ;ACvDD,YAAY,EAAC,oBAAoB,EAAC,MAAM,0BAA0B,CAAC","sources":["packages/@react-aria/actiongroup/src/packages/@react-aria/actiongroup/src/useActionGroup.ts","packages/@react-aria/actiongroup/src/packages/@react-aria/actiongroup/src/useActionGroupItem.ts","packages/@react-aria/actiongroup/src/packages/@react-aria/actiongroup/src/index.ts","packages/@react-aria/actiongroup/src/index.ts"],"sourcesContent":[null,null,null,"/*\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 */\nexport type {ActionGroupAria} from './useActionGroup';\nexport {useActionGroup} from './useActionGroup';\nexport {useActionGroupItem} from './useActionGroupItem';\nexport type {AriaActionGroupProps} from '@react-types/actiongroup';\nexport type {ActionGroupItemAria, AriaActionGroupItemProps} from './useActionGroupItem';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;;;;AA0BA;IACE,gBAAgB,EAAE,aAAa,CAAA;CAChC;AAED,+BAA+B,CAAC,EAAE,KAAK,EAAE,qBAAqB,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,gBAAgB,CAAC,GAAG,eAAe,CA6DxI;ACzED;IACE,GAAG,EAAE,GAAG,CAAA;CACT;AAED;IACE,WAAW,EAAE,aAAa,GAAG,UAAU,CAAA;CACxC;AASD,mCAAmC,CAAC,EAAE,KAAK,EAAE,wBAAwB,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,UAAU,gBAAgB,CAAC,GAAG,mBAAmB,CAoClJ;ACvDD,YAAY,EAAC,oBAAoB,EAAC,MAAM,0BAA0B,CAAC","sources":["packages/@react-aria/actiongroup/src/packages/@react-aria/actiongroup/src/useActionGroup.ts","packages/@react-aria/actiongroup/src/packages/@react-aria/actiongroup/src/useActionGroupItem.ts","packages/@react-aria/actiongroup/src/packages/@react-aria/actiongroup/src/index.ts","packages/@react-aria/actiongroup/src/index.ts"],"sourcesContent":[null,null,null,"/*\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 */\nexport type {ActionGroupAria} from './useActionGroup';\nexport {useActionGroup} from './useActionGroup';\nexport {useActionGroupItem} from './useActionGroupItem';\nexport type {AriaActionGroupProps} from '@react-types/actiongroup';\nexport type {ActionGroupItemAria, AriaActionGroupItemProps} from './useActionGroupItem';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/actiongroup",
3
- "version": "3.6.5-nightly.4274+6c61f5b1d",
3
+ "version": "3.7.0",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,15 +22,13 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-aria/focus": "3.0.0-nightly.2563+6c61f5b1d",
26
- "@react-aria/i18n": "3.0.0-nightly.2563+6c61f5b1d",
27
- "@react-aria/interactions": "3.0.0-nightly.2563+6c61f5b1d",
28
- "@react-aria/selection": "3.0.0-nightly.2563+6c61f5b1d",
29
- "@react-aria/utils": "3.0.0-nightly.2563+6c61f5b1d",
30
- "@react-stately/collections": "3.0.0-nightly.2563+6c61f5b1d",
31
- "@react-stately/list": "3.10.1-nightly.4274+6c61f5b1d",
32
- "@react-types/actiongroup": "3.4.6-nightly.4274+6c61f5b1d",
33
- "@react-types/shared": "3.0.0-nightly.2563+6c61f5b1d",
25
+ "@react-aria/focus": "^3.15.0",
26
+ "@react-aria/i18n": "^3.9.0",
27
+ "@react-aria/interactions": "^3.20.0",
28
+ "@react-aria/utils": "^3.22.0",
29
+ "@react-stately/list": "^3.10.1",
30
+ "@react-types/actiongroup": "^3.4.6",
31
+ "@react-types/shared": "^3.22.0",
34
32
  "@swc/helpers": "^0.5.0"
35
33
  },
36
34
  "peerDependencies": {
@@ -40,5 +38,5 @@
40
38
  "publishConfig": {
41
39
  "access": "public"
42
40
  },
43
- "gitHead": "6c61f5b1db5f52ebc654bf754a15594bb0662f6f"
41
+ "gitHead": "9ce2f674eab2cc8912800d3162dcf00a1ce94274"
44
42
  }
@@ -35,12 +35,9 @@ export function useActionGroup<T>(props: AriaActionGroupProps<T>, state: ListSta
35
35
  } = props;
36
36
 
37
37
  let [isInToolbar, setInToolbar] = useState(false);
38
- // should be safe because re-calling set state with the same value it already has is a no-op
39
- // this will allow us to react should a parent re-render and change its role though
40
- // eslint-disable-next-line react-hooks/exhaustive-deps
41
38
  useLayoutEffect(() => {
42
39
  setInToolbar(!!(ref.current && ref.current.parentElement?.closest('[role="toolbar"]')));
43
- });
40
+ }, [ref]);
44
41
 
45
42
  let allKeys = [...state.collection.getKeys()];
46
43
  if (!allKeys.some(key => !state.disabledKeys.has(key))) {