@react-aria/actiongroup 3.5.4-nightly.3937 → 3.5.4-nightly.3943

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
@@ -1,7 +1,7 @@
1
1
  import {createFocusManager as $1oG4F$createFocusManager} from "@react-aria/focus";
2
- import {filterDOMProps as $1oG4F$filterDOMProps, mergeProps as $1oG4F$mergeProps} from "@react-aria/utils";
2
+ import {filterDOMProps as $1oG4F$filterDOMProps, useEffectEvent as $1oG4F$useEffectEvent, mergeProps as $1oG4F$mergeProps} from "@react-aria/utils";
3
3
  import {useLocale as $1oG4F$useLocale} from "@react-aria/i18n";
4
- import {useRef as $1oG4F$useRef, useEffect as $1oG4F$useEffect} from "react";
4
+ import {useEffect as $1oG4F$useEffect} from "react";
5
5
 
6
6
  /*
7
7
  * Copyright 2020 Adobe. All rights reserved.
@@ -109,21 +109,17 @@ function $f0ac0fb73c3ec062$export$9597202bd3099a29(props, state, ref) {
109
109
  buttonProps["aria-checked"] = isSelected;
110
110
  }
111
111
  let isFocused = props.key === state.selectionManager.focusedKey;
112
- let lastRender = (0, $1oG4F$useRef)({
113
- isFocused: isFocused,
114
- state: state
112
+ let onRemovedWithFocus = (0, $1oG4F$useEffectEvent)(()=>{
113
+ if (isFocused) state.selectionManager.setFocusedKey(null);
115
114
  });
116
- lastRender.current = {
117
- isFocused: isFocused,
118
- state: state
119
- };
120
115
  // If the focused item is removed from the DOM, reset the focused key to null.
121
- // eslint-disable-next-line arrow-body-style
122
116
  (0, $1oG4F$useEffect)(()=>{
123
117
  return ()=>{
124
- if (lastRender.current.isFocused) lastRender.current.state.selectionManager.setFocusedKey(null);
118
+ onRemovedWithFocus();
125
119
  };
126
- }, []);
120
+ }, [
121
+ onRemovedWithFocus
122
+ ]);
127
123
  return {
128
124
  buttonProps: (0, $1oG4F$mergeProps)(buttonProps, {
129
125
  tabIndex: isFocused || state.selectionManager.focusedKey == null ? 0 : -1,
package/dist/main.js CHANGED
@@ -115,21 +115,17 @@ function $44b92e5de834b44e$export$9597202bd3099a29(props, state, ref) {
115
115
  buttonProps["aria-checked"] = isSelected;
116
116
  }
117
117
  let isFocused = props.key === state.selectionManager.focusedKey;
118
- let lastRender = (0, $hjKwo$react.useRef)({
119
- isFocused: isFocused,
120
- state: state
118
+ let onRemovedWithFocus = (0, $hjKwo$reactariautils.useEffectEvent)(()=>{
119
+ if (isFocused) state.selectionManager.setFocusedKey(null);
121
120
  });
122
- lastRender.current = {
123
- isFocused: isFocused,
124
- state: state
125
- };
126
121
  // If the focused item is removed from the DOM, reset the focused key to null.
127
- // eslint-disable-next-line arrow-body-style
128
122
  (0, $hjKwo$react.useEffect)(()=>{
129
123
  return ()=>{
130
- if (lastRender.current.isFocused) lastRender.current.state.selectionManager.setFocusedKey(null);
124
+ onRemovedWithFocus();
131
125
  };
132
- }, []);
126
+ }, [
127
+ onRemovedWithFocus
128
+ ]);
133
129
  return {
134
130
  buttonProps: (0, $hjKwo$reactariautils.mergeProps)(buttonProps, {
135
131
  tabIndex: isFocused || state.selectionManager.focusedKey == null ? 0 : -1,
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED;;;AASA,MAAM,2CAAqB;IACzB,QAAQ;IACR,UAAU;IACV,YAAY;AACd;AAMO,SAAS,0CAAkB,KAA8B,EAAE,KAAmB,EAAE,GAAgC,EAAmB;IACxI,IAAI,cACF,WAAU,eACV,cAAc,eACf,GAAG;IACJ,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,IAAI;IAGnB,IAAI,aAAC,UAAS,EAAC,GAAG,CAAA,GAAA,8BAAS,AAAD;IAC1B,IAAI,eAAe,CAAA,GAAA,wCA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,WAAW,CAAC,eAAe,GAAG;IAChC,CAAC;IAED,IAAI,YAAY,MAAM,GAAG,KAAK,MAAM,gBAAgB,CAAC,UAAU;IAC/D,IAAI,aAAa,CAAA,GAAA,mBAAK,EAAE;mBAAC;eAAW;IAAK;IACzC,WAAW,OAAO,GAAG;mBAAC;eAAW;IAAK;IAEtC,8EAA8E;IAC9E,4CAA4C;IAC5C,CAAA,GAAA,sBAAS,AAAD,EAAE,IAAM;QACd,OAAO,IAAM;YACX,IAAI,WAAW,OAAO,CAAC,SAAS,EAC9B,WAAW,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,aAAa,CAAC,IAAI;QAEhE;IACF,GAAG,EAAE;IAEL,OAAO;QACL,aAAa,CAAA,GAAA,gCAAU,AAAD,EAAE,aAAa;YACnC,UAAU,aAAa,MAAM,gBAAgB,CAAC,UAAU,IAAI,IAAI,GAAG,IAAI,EAAE;YACzE,WAAU;gBACR,MAAM,gBAAgB,CAAC,aAAa,CAAC,MAAM,GAAG;YAChD;YACA,WAAU;gBACR,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} from '@react-types/shared';\nimport {filterDOMProps} from '@react-aria/utils';\nimport {ListState} from '@react-stately/list';\nimport {Orientation} from '@react-types/shared';\nimport {RefObject} 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 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 = BUTTON_GROUP_ROLES[state.selectionManager.selectionMode];\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} from '@react-types/shared';\nimport {Key, RefObject, useEffect, useRef} from 'react';\nimport {ListState} from '@react-stately/list';\nimport {mergeProps} from '@react-aria/utils';\nimport {PressProps} from '@react-aria/interactions';\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 lastRender = useRef({isFocused, state});\n lastRender.current = {isFocused, state};\n\n // If the focused item is removed from the DOM, reset the focused key to null.\n // eslint-disable-next-line arrow-body-style\n useEffect(() => {\n return () => {\n if (lastRender.current.isFocused) {\n lastRender.current.state.selectionManager.setFocusedKey(null);\n }\n };\n }, []);\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,GAED;;;AASA,MAAM,2CAAqB;IACzB,QAAQ;IACR,UAAU;IACV,YAAY;AACd;AAMO,SAAS,0CAAkB,KAA8B,EAAE,KAAmB,EAAE,GAAgC,EAAmB;IACxI,IAAI,cACF,WAAU,eACV,cAAc,eACf,GAAG;IACJ,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,IAAI;IAGnB,IAAI,aAAC,UAAS,EAAC,GAAG,CAAA,GAAA,8BAAS,AAAD;IAC1B,IAAI,eAAe,CAAA,GAAA,wCAAiB,EAAE;IACtC,IAAI,gBAAgB,cAAc,SAAS,gBAAgB;IAC3D,IAAI,YAAY,CAAC,IAAM;QACrB,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;oBAAC,MAAM,IAAI;gBAAA;qBAEtC,aAAa,SAAS,CAAC;oBAAC,MAAM,IAAI;gBAAA;gBAEpC,KAAM;YACR,KAAK;YACL,KAAK;gBACH,EAAE,cAAc;gBAChB,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I,GAAG,IAAI,EAAE;YACzE,WAAU;gBACR,MAAM,gBAAgB,CAAC,aAAa,CAAC,MAAM,GAAG;YAChD;YACA,WAAU;gBACR,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} from '@react-types/shared';\nimport {filterDOMProps} from '@react-aria/utils';\nimport {ListState} from '@react-stately/list';\nimport {Orientation} from '@react-types/shared';\nimport {RefObject} 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 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 = BUTTON_GROUP_ROLES[state.selectionManager.selectionMode];\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} from '@react-types/shared';\nimport {Key, RefObject, useEffect} from 'react';\nimport {ListState} from '@react-stately/list';\nimport {mergeProps, useEffectEvent} from '@react-aria/utils';\nimport {PressProps} from '@react-aria/interactions';\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
@@ -1,7 +1,7 @@
1
1
  import {createFocusManager as $1oG4F$createFocusManager} from "@react-aria/focus";
2
- import {filterDOMProps as $1oG4F$filterDOMProps, mergeProps as $1oG4F$mergeProps} from "@react-aria/utils";
2
+ import {filterDOMProps as $1oG4F$filterDOMProps, useEffectEvent as $1oG4F$useEffectEvent, mergeProps as $1oG4F$mergeProps} from "@react-aria/utils";
3
3
  import {useLocale as $1oG4F$useLocale} from "@react-aria/i18n";
4
- import {useRef as $1oG4F$useRef, useEffect as $1oG4F$useEffect} from "react";
4
+ import {useEffect as $1oG4F$useEffect} from "react";
5
5
 
6
6
  /*
7
7
  * Copyright 2020 Adobe. All rights reserved.
@@ -109,21 +109,17 @@ function $f0ac0fb73c3ec062$export$9597202bd3099a29(props, state, ref) {
109
109
  buttonProps["aria-checked"] = isSelected;
110
110
  }
111
111
  let isFocused = props.key === state.selectionManager.focusedKey;
112
- let lastRender = (0, $1oG4F$useRef)({
113
- isFocused: isFocused,
114
- state: state
112
+ let onRemovedWithFocus = (0, $1oG4F$useEffectEvent)(()=>{
113
+ if (isFocused) state.selectionManager.setFocusedKey(null);
115
114
  });
116
- lastRender.current = {
117
- isFocused: isFocused,
118
- state: state
119
- };
120
115
  // If the focused item is removed from the DOM, reset the focused key to null.
121
- // eslint-disable-next-line arrow-body-style
122
116
  (0, $1oG4F$useEffect)(()=>{
123
117
  return ()=>{
124
- if (lastRender.current.isFocused) lastRender.current.state.selectionManager.setFocusedKey(null);
118
+ onRemovedWithFocus();
125
119
  };
126
- }, []);
120
+ }, [
121
+ onRemovedWithFocus
122
+ ]);
127
123
  return {
128
124
  buttonProps: (0, $1oG4F$mergeProps)(buttonProps, {
129
125
  tabIndex: isFocused || state.selectionManager.focusedKey == null ? 0 : -1,
@@ -1 +1 @@
1
- {"mappings":";;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED;;;AASA,MAAM,2CAAqB;IACzB,QAAQ;IACR,UAAU;IACV,YAAY;AACd;AAMO,SAAS,0CAAkB,KAA8B,EAAE,KAAmB,EAAE,GAAgC,EAAmB;IACxI,IAAI,cACF,WAAU,eACV,cAAc,eACf,GAAG;IACJ,IAAI,UAAU;WAAI,MAAM,UAAU,CAAC,OAAO;KAAG;IAC7C,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAA,MAAO,CAAC,MAAM,YAAY,CAAC,GAAG,CAAC,OAC/C,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cAAc;IACnC;IAEA,IAAI,kBAAkB,QAAQ;QAC5B,IAAI,aAAa,MAAM,gBAAgB,CAAC,UAAU,CAAC,MAAM,GAAG;QAC5D,WAAW,CAAC,eAAe,GAAG;IAChC,CAAC;IAED,IAAI,YAAY,MAAM,GAAG,KAAK,MAAM,gBAAgB,CAAC,UAAU;IAC/D,IAAI,aAAa,CAAA,GAAA,aAAK,EAAE;mBAAC;eAAW;IAAK;IACzC,WAAW,OAAO,GAAG;mBAAC;eAAW;IAAK;IAEtC,8EAA8E;IAC9E,4CAA4C;IAC5C,CAAA,GAAA,gBAAS,AAAD,EAAE,IAAM;QACd,OAAO,IAAM;YACX,IAAI,WAAW,OAAO,CAAC,SAAS,EAC9B,WAAW,OAAO,CAAC,KAAK,CAAC,gBAAgB,CAAC,aAAa,CAAC,IAAI;QAEhE;IACF,GAAG,EAAE;IAEL,OAAO;QACL,aAAa,CAAA,GAAA,iBAAU,AAAD,EAAE,aAAa;YACnC,UAAU,aAAa,MAAM,gBAAgB,CAAC,UAAU,IAAI,IAAI,GAAG,IAAI,EAAE;YACzE,WAAU;gBACR,MAAM,gBAAgB,CAAC,aAAa,CAAC,MAAM,GAAG;YAChD;YACA,WAAU;gBACR,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} from '@react-types/shared';\nimport {filterDOMProps} from '@react-aria/utils';\nimport {ListState} from '@react-stately/list';\nimport {Orientation} from '@react-types/shared';\nimport {RefObject} 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 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 = BUTTON_GROUP_ROLES[state.selectionManager.selectionMode];\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} from '@react-types/shared';\nimport {Key, RefObject, useEffect, useRef} from 'react';\nimport {ListState} from '@react-stately/list';\nimport {mergeProps} from '@react-aria/utils';\nimport {PressProps} from '@react-aria/interactions';\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 lastRender = useRef({isFocused, state});\n lastRender.current = {isFocused, state};\n\n // If the focused item is removed from the DOM, reset the focused key to null.\n // eslint-disable-next-line arrow-body-style\n useEffect(() => {\n return () => {\n if (lastRender.current.isFocused) {\n lastRender.current.state.selectionManager.setFocusedKey(null);\n }\n };\n }, []);\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
+ {"mappings":";;;;;AAAA;;;;;;;;;;ACAA;;;;;;;;;;CAUC,GAED;;;AASA,MAAM,2CAAqB;IACzB,QAAQ;IACR,UAAU;IACV,YAAY;AACd;AAMO,SAAS,0CAAkB,KAA8B,EAAE,KAAmB,EAAE,GAAgC,EAAmB;IACxI,IAAI,cACF,WAAU,eACV,cAAc,eACf,GAAG;IACJ,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,IAAI;IAGnB,IAAI,aAAC,UAAS,EAAC,GAAG,CAAA,GAAA,gBAAS,AAAD;IAC1B,IAAI,eAAe,CAAA,GAAA,yBAAiB,EAAE;IACtC,IAAI,gBAAgB,cAAc,SAAS,gBAAgB;IAC3D,IAAI,YAAY,CAAC,IAAM;QACrB,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;oBAAC,MAAM,IAAI;gBAAA;qBAEtC,aAAa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ACL,aAAa,CAAA,GAAA,iBAAU,AAAD,EAAE,aAAa;YACnC,UAAU,aAAa,MAAM,gBAAgB,CAAC,UAAU,IAAI,IAAI,GAAG,IAAI,EAAE;YACzE,WAAU;gBACR,MAAM,gBAAgB,CAAC,aAAa,CAAC,MAAM,GAAG;YAChD;YACA,WAAU;gBACR,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} from '@react-types/shared';\nimport {filterDOMProps} from '@react-aria/utils';\nimport {ListState} from '@react-stately/list';\nimport {Orientation} from '@react-types/shared';\nimport {RefObject} 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 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 = BUTTON_GROUP_ROLES[state.selectionManager.selectionMode];\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} from '@react-types/shared';\nimport {Key, RefObject, useEffect} from 'react';\nimport {ListState} from '@react-stately/list';\nimport {mergeProps, useEffectEvent} from '@react-aria/utils';\nimport {PressProps} from '@react-aria/interactions';\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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/actiongroup",
3
- "version": "3.5.4-nightly.3937+600bff46f",
3
+ "version": "3.5.4-nightly.3943+06e63d3ae",
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/focus": "3.0.0-nightly.2235+600bff46f",
26
- "@react-aria/i18n": "3.0.0-nightly.2235+600bff46f",
27
- "@react-aria/interactions": "3.0.0-nightly.2235+600bff46f",
28
- "@react-aria/selection": "3.0.0-nightly.2235+600bff46f",
29
- "@react-aria/utils": "3.0.0-nightly.2235+600bff46f",
30
- "@react-stately/collections": "3.0.0-nightly.2235+600bff46f",
31
- "@react-stately/list": "3.8.2-nightly.3937+600bff46f",
32
- "@react-types/actiongroup": "3.4.3-nightly.3937+600bff46f",
33
- "@react-types/shared": "3.0.0-nightly.2235+600bff46f",
25
+ "@react-aria/focus": "3.0.0-nightly.2241+06e63d3ae",
26
+ "@react-aria/i18n": "3.0.0-nightly.2241+06e63d3ae",
27
+ "@react-aria/interactions": "3.0.0-nightly.2241+06e63d3ae",
28
+ "@react-aria/selection": "3.0.0-nightly.2241+06e63d3ae",
29
+ "@react-aria/utils": "3.0.0-nightly.2241+06e63d3ae",
30
+ "@react-stately/collections": "3.0.0-nightly.2241+06e63d3ae",
31
+ "@react-stately/list": "3.8.2-nightly.3943+06e63d3ae",
32
+ "@react-types/actiongroup": "3.4.3-nightly.3943+06e63d3ae",
33
+ "@react-types/shared": "3.0.0-nightly.2241+06e63d3ae",
34
34
  "@swc/helpers": "^0.4.14"
35
35
  },
36
36
  "peerDependencies": {
@@ -39,5 +39,5 @@
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
- "gitHead": "600bff46f77558d68aff7ea2c002873653f0330d"
42
+ "gitHead": "06e63d3ae7898b8cd81fdb6fa87b763faf2054bf"
43
43
  }
@@ -11,9 +11,9 @@
11
11
  */
12
12
 
13
13
  import {DOMAttributes, FocusableElement} from '@react-types/shared';
14
- import {Key, RefObject, useEffect, useRef} from 'react';
14
+ import {Key, RefObject, useEffect} from 'react';
15
15
  import {ListState} from '@react-stately/list';
16
- import {mergeProps} from '@react-aria/utils';
16
+ import {mergeProps, useEffectEvent} from '@react-aria/utils';
17
17
  import {PressProps} from '@react-aria/interactions';
18
18
 
19
19
  export interface AriaActionGroupItemProps {
@@ -43,18 +43,18 @@ export function useActionGroupItem<T>(props: AriaActionGroupItemProps, state: Li
43
43
  }
44
44
 
45
45
  let isFocused = props.key === state.selectionManager.focusedKey;
46
- let lastRender = useRef({isFocused, state});
47
- lastRender.current = {isFocused, state};
46
+ let onRemovedWithFocus = useEffectEvent(() => {
47
+ if (isFocused) {
48
+ state.selectionManager.setFocusedKey(null);
49
+ }
50
+ });
48
51
 
49
52
  // If the focused item is removed from the DOM, reset the focused key to null.
50
- // eslint-disable-next-line arrow-body-style
51
53
  useEffect(() => {
52
54
  return () => {
53
- if (lastRender.current.isFocused) {
54
- lastRender.current.state.selectionManager.setFocusedKey(null);
55
- }
55
+ onRemovedWithFocus();
56
56
  };
57
- }, []);
57
+ }, [onRemovedWithFocus]);
58
58
 
59
59
  return {
60
60
  buttonProps: mergeProps(buttonProps, {