Focus first selectable element in preferences pane
This commit is contained in:
parent
078b176ec6
commit
e8a3dc5db6
6 changed files with 106 additions and 48 deletions
|
@ -781,6 +781,17 @@ Signal Desktop makes use of the following open source projects.
|
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
## focusable-selectors
|
||||
|
||||
The MIT License (MIT)
|
||||
Copyright (c) 2021 Kitty Giraudel
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
## form-data
|
||||
|
||||
Copyright (c) 2012 Felix Geisendörfer (felix@debuggable.com) and contributors
|
||||
|
|
|
@ -114,6 +114,7 @@
|
|||
"filesize": "3.6.1",
|
||||
"firstline": "1.2.1",
|
||||
"focus-trap-react": "8.8.1",
|
||||
"focusable-selectors": "0.8.0",
|
||||
"form-data": "4.0.0",
|
||||
"fs-extra": "5.0.0",
|
||||
"fuse.js": "6.5.3",
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import React, { useMemo } from 'react';
|
||||
import React, { forwardRef, useMemo } from 'react';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
|
||||
import { getClassNamesFor } from '../util/getClassNamesFor';
|
||||
|
@ -24,18 +24,21 @@ export type PropsType = {
|
|||
onClick?: () => unknown;
|
||||
};
|
||||
|
||||
export function Checkbox({
|
||||
checked,
|
||||
children,
|
||||
description,
|
||||
disabled,
|
||||
isRadio,
|
||||
label,
|
||||
moduleClassName,
|
||||
name,
|
||||
onChange,
|
||||
onClick,
|
||||
}: PropsType): JSX.Element {
|
||||
export const Checkbox = forwardRef(function CheckboxInner(
|
||||
{
|
||||
checked,
|
||||
children,
|
||||
description,
|
||||
disabled,
|
||||
isRadio,
|
||||
label,
|
||||
moduleClassName,
|
||||
name,
|
||||
onChange,
|
||||
onClick,
|
||||
}: PropsType,
|
||||
ref: React.Ref<HTMLInputElement>
|
||||
): JSX.Element {
|
||||
const getClassName = getClassNamesFor('Checkbox', moduleClassName);
|
||||
const id = useMemo(() => `${name}::${uuid()}`, [name]);
|
||||
|
||||
|
@ -48,6 +51,7 @@ export function Checkbox({
|
|||
name={name}
|
||||
onChange={ev => onChange(ev.target.checked)}
|
||||
onClick={onClick}
|
||||
ref={ref}
|
||||
type={isRadio ? 'radio' : 'checkbox'}
|
||||
/>
|
||||
</div>
|
||||
|
@ -76,4 +80,4 @@ export function Checkbox({
|
|||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -3,7 +3,14 @@
|
|||
|
||||
import type { AudioDevice } from '@signalapp/ringrtc';
|
||||
import type { ReactNode } from 'react';
|
||||
import React, { useEffect, useState, useCallback, useMemo } from 'react';
|
||||
import focusableSelectors from 'focusable-selectors';
|
||||
import React, {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import { noop } from 'lodash';
|
||||
import classNames from 'classnames';
|
||||
import uuid from 'uuid';
|
||||
|
@ -354,6 +361,27 @@ export function Preferences({
|
|||
[onSelectedMicrophoneChange, availableMicrophones]
|
||||
);
|
||||
|
||||
const selectors = useMemo(() => focusableSelectors.join(','), []);
|
||||
const settingsPaneRef = useRef<HTMLDivElement | null>(null);
|
||||
useEffect(() => {
|
||||
const settingsPane = settingsPaneRef.current;
|
||||
if (!settingsPane) {
|
||||
return;
|
||||
}
|
||||
|
||||
const elements = settingsPane.querySelectorAll<
|
||||
| HTMLAnchorElement
|
||||
| HTMLButtonElement
|
||||
| HTMLInputElement
|
||||
| HTMLSelectElement
|
||||
| HTMLTextAreaElement
|
||||
>(selectors);
|
||||
if (!elements.length) {
|
||||
return;
|
||||
}
|
||||
elements[0]?.focus();
|
||||
}, [page, selectors]);
|
||||
|
||||
const onAudioOutputSelectChange = useCallback(
|
||||
(value: string) => {
|
||||
if (value === 'undefined') {
|
||||
|
@ -1278,7 +1306,9 @@ export function Preferences({
|
|||
{i18n('icu:Preferences__button--privacy')}
|
||||
</button>
|
||||
</div>
|
||||
<div className="Preferences__settings-pane">{settings}</div>
|
||||
<div className="Preferences__settings-pane" ref={settingsPaneRef}>
|
||||
{settings}
|
||||
</div>
|
||||
</div>
|
||||
</TitleBarContainer>
|
||||
);
|
||||
|
|
|
@ -689,6 +689,14 @@
|
|||
"reasonCategory": "falseMatch",
|
||||
"updated": "2018-09-15T00:38:04.183Z"
|
||||
},
|
||||
{
|
||||
"rule": "thenify-multiArgs",
|
||||
"path": "node_modules/default-browser-id/node_modules/pify/index.js",
|
||||
"line": "\t\t\t\t} else if (opts.multiArgs) {",
|
||||
"reasonCategory": "falseMatch|testCode|exampleCode|otherUtilityCode|regexMatchedSafeCode|notExercisedByOurApp|ruleNeeded|usageTrusted",
|
||||
"updated": "2023-04-20T16:43:40.643Z",
|
||||
"reasonDetail": "<optional>"
|
||||
},
|
||||
{
|
||||
"rule": "DOM-outerHTML",
|
||||
"path": "node_modules/domutils/node_modules/dom-serializer/lib/esm/index.js",
|
||||
|
@ -2184,6 +2192,13 @@
|
|||
"updated": "2022-09-14T16:20:15.384Z",
|
||||
"reasonDetail": "Holds a reference to a container element to prevent outside clicks"
|
||||
},
|
||||
{
|
||||
"rule": "React-useRef",
|
||||
"path": "ts/components/Preferences.tsx",
|
||||
"line": " const settingsPaneRef = useRef<HTMLDivElement | null>(null);",
|
||||
"reasonCategory": "usageTrusted",
|
||||
"updated": "2023-04-21T02:12:22.352Z"
|
||||
},
|
||||
{
|
||||
"rule": "React-useRef",
|
||||
"path": "ts/components/ProfileEditor.tsx",
|
||||
|
@ -2351,6 +2366,14 @@
|
|||
"reasonCategory": "usageTrusted",
|
||||
"updated": "2021-07-30T16:57:33.618Z"
|
||||
},
|
||||
{
|
||||
"rule": "React-useRef",
|
||||
"path": "ts/components/conversation/InlineNotificationWrapper.tsx",
|
||||
"line": " const focusRef = useRef<HTMLDivElement>(null);",
|
||||
"reasonCategory": "falseMatch|testCode|exampleCode|otherUtilityCode|regexMatchedSafeCode|notExercisedByOurApp|ruleNeeded|usageTrusted",
|
||||
"updated": "2023-04-12T15:51:28.066Z",
|
||||
"reasonDetail": "<optional>"
|
||||
},
|
||||
{
|
||||
"rule": "React-createRef",
|
||||
"path": "ts/components/conversation/Message.tsx",
|
||||
|
@ -2375,6 +2398,22 @@
|
|||
"updated": "2021-03-05T19:57:01.431Z",
|
||||
"reasonDetail": "Used for propagating click from the Message to MessageAudio's button"
|
||||
},
|
||||
{
|
||||
"rule": "React-useRef",
|
||||
"path": "ts/components/conversation/MessageDetail.tsx",
|
||||
"line": " const focusRef = useRef<HTMLDivElement>(null);",
|
||||
"reasonCategory": "falseMatch|testCode|exampleCode|otherUtilityCode|regexMatchedSafeCode|notExercisedByOurApp|ruleNeeded|usageTrusted",
|
||||
"updated": "2023-04-12T15:51:28.066Z",
|
||||
"reasonDetail": "<optional>"
|
||||
},
|
||||
{
|
||||
"rule": "React-useRef",
|
||||
"path": "ts/components/conversation/MessageDetail.tsx",
|
||||
"line": " const messageContainerRef = useRef<HTMLDivElement>(null);",
|
||||
"reasonCategory": "falseMatch|testCode|exampleCode|otherUtilityCode|regexMatchedSafeCode|notExercisedByOurApp|ruleNeeded|usageTrusted",
|
||||
"updated": "2023-04-12T15:51:28.066Z",
|
||||
"reasonDetail": "<optional>"
|
||||
},
|
||||
{
|
||||
"rule": "React-useRef",
|
||||
"path": "ts/components/conversation/Quote.tsx",
|
||||
|
@ -2528,37 +2567,5 @@
|
|||
"line": " message.innerHTML = window.i18n('icu:optimizingApplication');",
|
||||
"reasonCategory": "usageTrusted",
|
||||
"updated": "2021-09-17T21:02:59.414Z"
|
||||
},
|
||||
{
|
||||
"rule": "React-useRef",
|
||||
"path": "ts/components/conversation/InlineNotificationWrapper.tsx",
|
||||
"line": " const focusRef = useRef<HTMLDivElement>(null);",
|
||||
"reasonCategory": "falseMatch|testCode|exampleCode|otherUtilityCode|regexMatchedSafeCode|notExercisedByOurApp|ruleNeeded|usageTrusted",
|
||||
"updated": "2023-04-12T15:51:28.066Z",
|
||||
"reasonDetail": "<optional>"
|
||||
},
|
||||
{
|
||||
"rule": "React-useRef",
|
||||
"path": "ts/components/conversation/MessageDetail.tsx",
|
||||
"line": " const focusRef = useRef<HTMLDivElement>(null);",
|
||||
"reasonCategory": "falseMatch|testCode|exampleCode|otherUtilityCode|regexMatchedSafeCode|notExercisedByOurApp|ruleNeeded|usageTrusted",
|
||||
"updated": "2023-04-12T15:51:28.066Z",
|
||||
"reasonDetail": "<optional>"
|
||||
},
|
||||
{
|
||||
"rule": "React-useRef",
|
||||
"path": "ts/components/conversation/MessageDetail.tsx",
|
||||
"line": " const messageContainerRef = useRef<HTMLDivElement>(null);",
|
||||
"reasonCategory": "falseMatch|testCode|exampleCode|otherUtilityCode|regexMatchedSafeCode|notExercisedByOurApp|ruleNeeded|usageTrusted",
|
||||
"updated": "2023-04-12T15:51:28.066Z",
|
||||
"reasonDetail": "<optional>"
|
||||
},
|
||||
{
|
||||
"rule": "thenify-multiArgs",
|
||||
"path": "node_modules/default-browser-id/node_modules/pify/index.js",
|
||||
"line": "\t\t\t\t} else if (opts.multiArgs) {",
|
||||
"reasonCategory": "falseMatch|testCode|exampleCode|otherUtilityCode|regexMatchedSafeCode|notExercisedByOurApp|ruleNeeded|usageTrusted",
|
||||
"updated": "2023-04-20T16:43:40.643Z",
|
||||
"reasonDetail": "<optional>"
|
||||
}
|
||||
]
|
||||
|
|
|
@ -9488,6 +9488,11 @@ focus-trap@^6.7.1:
|
|||
dependencies:
|
||||
tabbable "^5.2.1"
|
||||
|
||||
focusable-selectors@0.8.0:
|
||||
version "0.8.0"
|
||||
resolved "https://registry.yarnpkg.com/focusable-selectors/-/focusable-selectors-0.8.0.tgz#aecfd7ce2ac369fd808289d4bcf474ac2bf03562"
|
||||
integrity sha512-lKyq/Cth8mTEzJk2CLHLdMDYl2zmMicQflfrUMs0CZ3Boc5Ca/63d7z+GgKV3nKm79KqrPtCWrwTdoV9RTjVCA==
|
||||
|
||||
follow-redirects@^1.0.0:
|
||||
version "1.14.9"
|
||||
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7"
|
||||
|
|
Loading…
Reference in a new issue