Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Web - Members page search bar does not get focused #27497

Merged
merged 22 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/components/SelectionList/BaseSelectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ function BaseSelectionList({
showScrollIndicator = false,
showLoadingPlaceholder = false,
showConfirmButton = false,
shouldFocusOnSelectRow = false,
isKeyboardShown = false,
inputRef = null,
disableKeyboardShortcuts = false,
children,
}) {
Expand All @@ -65,7 +67,6 @@ function BaseSelectionList({
const shouldShowSelectAll = Boolean(onSelectAll);
const activeElement = useActiveElement();
const isFocused = useIsFocused();

/**
* Iterates through the sections and items inside each section, and builds 3 arrays along the way:
* - `allOptions`: Contains all the items in the list, flattened, regardless of section
Expand Down Expand Up @@ -209,6 +210,17 @@ function BaseSelectionList({
}

onSelectRow(item);

if (shouldShowTextInput && shouldFocusOnSelectRow && textInputRef.current) {
textInputRef.current.focus();
}
};

const selectAllRow = () => {
onSelectAll();
if (shouldShowTextInput && shouldFocusOnSelectRow && textInputRef.current) {
textInputRef.current.focus();
}
};

const selectFocusedOption = () => {
Expand Down Expand Up @@ -349,7 +361,13 @@ function BaseSelectionList({
{shouldShowTextInput && (
<View style={[styles.ph5, styles.pb3]}>
<TextInput
ref={textInputRef}
ref={(el) => {
if (inputRef) {
// eslint-disable-next-line no-param-reassign
inputRef.current = el;
}
textInputRef.current = el;
}}
label={textInputLabel}
accessibilityLabel={textInputLabel}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT}
Expand All @@ -376,7 +394,7 @@ function BaseSelectionList({
{!headerMessage && canSelectMultiple && shouldShowSelectAll && (
<PressableWithFeedback
style={[styles.peopleRow, styles.userSelectNone, styles.ph5, styles.pb3]}
onPress={onSelectAll}
onPress={selectAllRow}
accessibilityLabel={translate('workspace.people.selectAll')}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
accessibilityState={{checked: flattenedSections.allSelected}}
Expand All @@ -386,7 +404,7 @@ function BaseSelectionList({
<Checkbox
accessibilityLabel={translate('workspace.people.selectAll')}
isChecked={flattenedSections.allSelected}
onPress={onSelectAll}
onPress={selectAllRow}
disabled={flattenedSections.allOptions.length === flattenedSections.disabledOptionsIndexes.length}
/>
<View style={[styles.flex1]}>
Expand Down
6 changes: 6 additions & 0 deletions src/components/SelectionList/selectionListPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ const propTypes = {
/** Whether to show the default confirm button */
showConfirmButton: PropTypes.bool,

/** Whether to focus the textinput after an option is selected */
shouldFocusOnSelectRow: PropTypes.bool,

/** A ref to forward to the TextInput */
inputRef: PropTypes.oneOfType([PropTypes.object]),

/** Custom content to display in the footer */
footerContent: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
};
Expand Down
16 changes: 14 additions & 2 deletions src/pages/workspace/WorkspaceMembersPage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useCallback, useEffect, useState, useMemo} from 'react';
import React, {useCallback, useEffect, useState, useMemo, useRef} from 'react';
import _ from 'underscore';
import lodashGet from 'lodash/get';
import {View} from 'react-native';
import {InteractionManager, View} from 'react-native';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import styles from '../../styles/styles';
Expand Down Expand Up @@ -31,6 +31,7 @@ import Log from '../../libs/Log';
import * as PersonalDetailsUtils from '../../libs/PersonalDetailsUtils';
import SelectionList from '../../components/SelectionList';
import Text from '../../components/Text';
import * as Browser from '../../libs/Browser';

const propTypes = {
/** All personal details asssociated with user */
Expand Down Expand Up @@ -77,6 +78,7 @@ function WorkspaceMembersPage(props) {
const prevIsOffline = usePrevious(props.network.isOffline);
const accountIDs = useMemo(() => _.keys(props.policyMembers), [props.policyMembers]);
const prevAccountIDs = usePrevious(accountIDs);
const textInputRef = useRef(null);

/**
* Get members for the current workspace
Expand Down Expand Up @@ -372,6 +374,14 @@ function WorkspaceMembersPage(props) {
prompt={props.translate('workspace.people.removeMembersPrompt')}
confirmText={props.translate('common.remove')}
cancelText={props.translate('common.cancel')}
onModalHide={() =>
InteractionManager.runAfterInteractions(() => {
if (!textInputRef.current) {
return;
}
textInputRef.current.focus();
})
}
/>
<View style={[styles.w100, styles.flex1]}>
<View style={[styles.w100, styles.flexRow, styles.pt3, styles.ph5]}>
Expand Down Expand Up @@ -403,6 +413,8 @@ function WorkspaceMembersPage(props) {
onDismissError={dismissError}
showLoadingPlaceholder={!OptionsListUtils.isPersonalDetailsReady(props.personalDetails) || _.isEmpty(props.policyMembers)}
showScrollIndicator
shouldFocusOnSelectRow={!Browser.isMobile()}
inputRef={textInputRef}
/>
</View>
</View>
Expand Down
Loading