Skip to content

Commit 1842f2e

Browse files
committed
prevent cmd + a from triggering select all items
1 parent 3ac236e commit 1842f2e

File tree

6 files changed

+39
-14
lines changed

6 files changed

+39
-14
lines changed

packages/@react-aria/autocomplete/src/useAutocomplete.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import {AriaLabelingProps, BaseEvent, DOMProps, RefObject} from '@react-types/shared';
1414
import {AutocompleteProps, AutocompleteState} from '@react-stately/autocomplete';
1515
import {ChangeEvent, InputHTMLAttributes, KeyboardEvent as ReactKeyboardEvent, useCallback, useEffect, useMemo, useRef} from 'react';
16-
import {CLEAR_FOCUS_EVENT, FOCUS_EVENT, mergeProps, mergeRefs, UPDATE_ACTIVEDESCENDANT, useEffectEvent, useId, useLabels, useObjectRef} from '@react-aria/utils';
16+
import {CLEAR_FOCUS_EVENT, FOCUS_EVENT, isCtrlKeyPressed, mergeProps, mergeRefs, UPDATE_ACTIVEDESCENDANT, useEffectEvent, useId, useLabels, useObjectRef} from '@react-aria/utils';
1717
// @ts-ignore
1818
import intlMessages from '../intl/*.json';
1919
import {useKeyboard} from '@react-aria/interactions';
@@ -150,6 +150,11 @@ export function UNSTABLE_useAutocomplete(props: AriaAutocompleteOptions, state:
150150
}
151151

152152
switch (e.key) {
153+
case 'a':
154+
if (isCtrlKeyPressed(e)) {
155+
return;
156+
}
157+
break;
153158
case 'Escape':
154159
// Early return for Escape here so it doesn't leak the Escape event from the simulated collection event below and
155160
// close the dialog prematurely. Ideally that should be up to the discretion of the input element hence the check

packages/@react-aria/selection/src/useSelectableCollection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import {CLEAR_FOCUS_EVENT, FOCUS_EVENT, focusWithoutScrolling, mergeProps, scrollIntoView, scrollIntoViewport, UPDATE_ACTIVEDESCENDANT, useEffectEvent, useEvent, useRouter, useUpdateEffect} from '@react-aria/utils';
13+
import {CLEAR_FOCUS_EVENT, FOCUS_EVENT, focusWithoutScrolling, isCtrlKeyPressed, mergeProps, scrollIntoView, scrollIntoViewport, UPDATE_ACTIVEDESCENDANT, useEffectEvent, useEvent, useRouter, useUpdateEffect} from '@react-aria/utils';
1414
import {DOMAttributes, FocusableElement, FocusStrategy, Key, KeyboardDelegate, RefObject} from '@react-types/shared';
1515
import {flushSync} from 'react-dom';
1616
import {FocusEvent, KeyboardEvent, useEffect, useRef} from 'react';
1717
import {focusSafely, getFocusableTreeWalker} from '@react-aria/focus';
1818
import {getInteractionModality} from '@react-aria/interactions';
19-
import {isCtrlKeyPressed, isNonContiguousSelectionModifier} from './utils';
19+
import {isNonContiguousSelectionModifier} from './utils';
2020
import {MultipleSelectionManager} from '@react-stately/selection';
2121
import {useLocale} from '@react-aria/i18n';
2222
import {useTypeSelect} from './useTypeSelect';

packages/@react-aria/selection/src/useSelectableItem.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
import {DOMAttributes, DOMProps, FocusableElement, Key, LongPressEvent, PointerType, PressEvent, RefObject} from '@react-types/shared';
1414
import {focusSafely} from '@react-aria/focus';
15-
import {isCtrlKeyPressed, isNonContiguousSelectionModifier} from './utils';
16-
import {mergeProps, openLink, UPDATE_ACTIVEDESCENDANT, useId, useRouter} from '@react-aria/utils';
15+
import {isCtrlKeyPressed, mergeProps, openLink, UPDATE_ACTIVEDESCENDANT, useId, useRouter} from '@react-aria/utils';
16+
import {isNonContiguousSelectionModifier} from './utils';
1717
import {MultipleSelectionManager} from '@react-stately/selection';
1818
import {PressProps, useLongPress, usePress} from '@react-aria/interactions';
1919
import {useEffect, useRef} from 'react';

packages/@react-aria/selection/src/utils.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import {isAppleDevice, isMac} from '@react-aria/utils';
13+
import {isAppleDevice} from '@react-aria/utils';
1414

1515
interface Event {
1616
altKey: boolean,
@@ -23,11 +23,3 @@ export function isNonContiguousSelectionModifier(e: Event) {
2323
// On Windows and Ubuntu, Alt + Space has a system wide meaning.
2424
return isAppleDevice() ? e.altKey : e.ctrlKey;
2525
}
26-
27-
export function isCtrlKeyPressed(e: Event) {
28-
if (isMac()) {
29-
return e.metaKey;
30-
}
31-
32-
return e.ctrlKey;
33-
}

packages/@react-aria/utils/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ export {useDeepMemo} from './useDeepMemo';
4343
export {useFormReset} from './useFormReset';
4444
export {useLoadMore} from './useLoadMore';
4545
export {CLEAR_FOCUS_EVENT, FOCUS_EVENT, UPDATE_ACTIVEDESCENDANT} from './constants';
46+
export {isCtrlKeyPressed} from './keyboard';
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2024 Adobe. All rights reserved.
3+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License. You may obtain a copy
5+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
*
7+
* Unless required by applicable law or agreed to in writing, software distributed under
8+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9+
* OF ANY KIND, either express or implied. See the License for the specific language
10+
* governing permissions and limitations under the License.
11+
*/
12+
13+
import {isMac} from './platform';
14+
15+
interface Event {
16+
altKey: boolean,
17+
ctrlKey: boolean,
18+
metaKey: boolean
19+
}
20+
21+
export function isCtrlKeyPressed(e: Event) {
22+
if (isMac()) {
23+
return e.metaKey;
24+
}
25+
26+
return e.ctrlKey;
27+
}

0 commit comments

Comments
 (0)