Edit group title/description: fix focus issues
This commit is contained in:
parent
e61354fd55
commit
2d6b0ecfe9
4 changed files with 34 additions and 11 deletions
|
@ -148,9 +148,11 @@ export const ConversationDetails: React.ComponentType<Props> = ({
|
||||||
modalNode = (
|
modalNode = (
|
||||||
<EditConversationAttributesModal
|
<EditConversationAttributesModal
|
||||||
avatarPath={conversation.avatarPath}
|
avatarPath={conversation.avatarPath}
|
||||||
focusDescription={modalState === ModalState.EditingGroupDescription}
|
|
||||||
groupDescription={conversation.groupDescription}
|
groupDescription={conversation.groupDescription}
|
||||||
i18n={i18n}
|
i18n={i18n}
|
||||||
|
initiallyFocusDescription={
|
||||||
|
modalState === ModalState.EditingGroupDescription
|
||||||
|
}
|
||||||
makeRequest={async (
|
makeRequest={async (
|
||||||
options: Readonly<{
|
options: Readonly<{
|
||||||
avatar?: undefined | ArrayBuffer;
|
avatar?: undefined | ArrayBuffer;
|
||||||
|
|
|
@ -23,6 +23,7 @@ type PropsType = ComponentProps<typeof EditConversationAttributesModal>;
|
||||||
const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
|
const createProps = (overrideProps: Partial<PropsType> = {}): PropsType => ({
|
||||||
avatarPath: undefined,
|
avatarPath: undefined,
|
||||||
i18n,
|
i18n,
|
||||||
|
initiallyFocusDescription: false,
|
||||||
onClose: action('onClose'),
|
onClose: action('onClose'),
|
||||||
makeRequest: action('onMakeRequest'),
|
makeRequest: action('onMakeRequest'),
|
||||||
requestState: RequestState.Inactive,
|
requestState: RequestState.Inactive,
|
||||||
|
@ -42,6 +43,12 @@ story.add('Avatar and title', () => (
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|
||||||
|
story.add('Initially focusing description', () => (
|
||||||
|
<EditConversationAttributesModal
|
||||||
|
{...createProps({ title: 'Has title', initiallyFocusDescription: true })}
|
||||||
|
/>
|
||||||
|
));
|
||||||
|
|
||||||
story.add('Request active', () => (
|
story.add('Request active', () => (
|
||||||
<EditConversationAttributesModal
|
<EditConversationAttributesModal
|
||||||
{...createProps({ requestState: RequestState.Active })}
|
{...createProps({ requestState: RequestState.Active })}
|
||||||
|
|
|
@ -25,9 +25,9 @@ const TEMPORARY_AVATAR_VALUE = new ArrayBuffer(0);
|
||||||
|
|
||||||
type PropsType = {
|
type PropsType = {
|
||||||
avatarPath?: string;
|
avatarPath?: string;
|
||||||
focusDescription?: boolean;
|
|
||||||
groupDescription?: string;
|
groupDescription?: string;
|
||||||
i18n: LocalizerType;
|
i18n: LocalizerType;
|
||||||
|
initiallyFocusDescription: boolean;
|
||||||
makeRequest: (
|
makeRequest: (
|
||||||
_: Readonly<{
|
_: Readonly<{
|
||||||
avatar?: undefined | ArrayBuffer;
|
avatar?: undefined | ArrayBuffer;
|
||||||
|
@ -40,22 +40,21 @@ type PropsType = {
|
||||||
title: string;
|
title: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
function focusRef(el: HTMLElement | null) {
|
|
||||||
if (el) {
|
|
||||||
el.focus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const EditConversationAttributesModal: FunctionComponent<PropsType> = ({
|
export const EditConversationAttributesModal: FunctionComponent<PropsType> = ({
|
||||||
avatarPath: externalAvatarPath,
|
avatarPath: externalAvatarPath,
|
||||||
focusDescription = false,
|
|
||||||
groupDescription: externalGroupDescription = '',
|
groupDescription: externalGroupDescription = '',
|
||||||
i18n,
|
i18n,
|
||||||
|
initiallyFocusDescription,
|
||||||
makeRequest,
|
makeRequest,
|
||||||
onClose,
|
onClose,
|
||||||
requestState,
|
requestState,
|
||||||
title: externalTitle,
|
title: externalTitle,
|
||||||
}) => {
|
}) => {
|
||||||
|
const focusDescriptionRef = useRef<undefined | boolean>(
|
||||||
|
initiallyFocusDescription
|
||||||
|
);
|
||||||
|
const focusDescription = focusDescriptionRef.current;
|
||||||
|
|
||||||
const startingTitleRef = useRef<string>(externalTitle);
|
const startingTitleRef = useRef<string>(externalTitle);
|
||||||
const startingAvatarPathRef = useRef<undefined | string>(externalAvatarPath);
|
const startingAvatarPathRef = useRef<undefined | string>(externalAvatarPath);
|
||||||
|
|
||||||
|
@ -71,6 +70,13 @@ export const EditConversationAttributesModal: FunctionComponent<PropsType> = ({
|
||||||
const trimmedTitle = rawTitle.trim();
|
const trimmedTitle = rawTitle.trim();
|
||||||
const trimmedDescription = rawGroupDescription.trim();
|
const trimmedDescription = rawGroupDescription.trim();
|
||||||
|
|
||||||
|
const focusRef = (el: null | HTMLElement) => {
|
||||||
|
if (el) {
|
||||||
|
el.focus();
|
||||||
|
focusDescriptionRef.current = undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const startingAvatarPath = startingAvatarPathRef.current;
|
const startingAvatarPath = startingAvatarPathRef.current;
|
||||||
if (!startingAvatarPath) {
|
if (!startingAvatarPath) {
|
||||||
|
@ -164,7 +170,7 @@ export const EditConversationAttributesModal: FunctionComponent<PropsType> = ({
|
||||||
disabled={isRequestActive}
|
disabled={isRequestActive}
|
||||||
i18n={i18n}
|
i18n={i18n}
|
||||||
onChangeValue={setRawTitle}
|
onChangeValue={setRawTitle}
|
||||||
ref={!focusDescription ? focusRef : undefined}
|
ref={focusDescription === false ? focusRef : undefined}
|
||||||
value={rawTitle}
|
value={rawTitle}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
@ -172,7 +178,7 @@ export const EditConversationAttributesModal: FunctionComponent<PropsType> = ({
|
||||||
disabled={isRequestActive}
|
disabled={isRequestActive}
|
||||||
i18n={i18n}
|
i18n={i18n}
|
||||||
onChangeValue={setRawGroupDescription}
|
onChangeValue={setRawGroupDescription}
|
||||||
ref={focusDescription ? focusRef : undefined}
|
ref={focusDescription === true ? focusRef : undefined}
|
||||||
value={rawGroupDescription}
|
value={rawGroupDescription}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
|
@ -14123,6 +14123,14 @@
|
||||||
"updated": "2021-03-05T22:52:40.572Z",
|
"updated": "2021-03-05T22:52:40.572Z",
|
||||||
"reasonDetail": "Doesn't interact with the DOM."
|
"reasonDetail": "Doesn't interact with the DOM."
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"rule": "React-useRef",
|
||||||
|
"path": "ts/components/conversation/conversation-details/EditConversationAttributesModal.js",
|
||||||
|
"line": " const focusDescriptionRef = react_1.useRef(initiallyFocusDescription);",
|
||||||
|
"reasonCategory": "usageTrusted",
|
||||||
|
"updated": "2021-06-04T14:19:49.714Z",
|
||||||
|
"reasonDetail": "Only stores undefined/true/false, not DOM references."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"rule": "React-createRef",
|
"rule": "React-createRef",
|
||||||
"path": "ts/components/conversation/media-gallery/MediaGallery.js",
|
"path": "ts/components/conversation/media-gallery/MediaGallery.js",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue