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

feat(selection-list): add tooltip #26091

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 6 additions & 1 deletion src/components/SelectionList/BaseSelectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,11 @@ function BaseSelectionList({
};

const renderItem = ({item, index, section}) => {
const normalizedIndex = index + lodashGet(section, 'indexOffset', 0);
const isDisabled = section.isDisabled;
const isFocused = !isDisabled && focusedIndex === index + lodashGet(section, 'indexOffset', 0);
const isFocused = !isDisabled && focusedIndex === normalizedIndex;
// We only create tooltips for the first 10 users or so since some reports have hundreds of users, causing performance to degrade.
const showTooltip = normalizedIndex < 10;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since SelectionList is used for other, non-user lists, this caused issues (#33172) where it's unexpected to limit tooltips to the first 10 items.


if (canSelectMultiple) {
thiagobrez marked this conversation as resolved.
Show resolved Hide resolved
return (
Expand All @@ -252,6 +255,7 @@ function BaseSelectionList({
isFocused={isFocused}
onSelectRow={() => selectRow(item, index)}
onDismissError={onDismissError}
showTooltip={showTooltip}
/>
);
}
Expand All @@ -262,6 +266,7 @@ function BaseSelectionList({
isFocused={isFocused}
isDisabled={isDisabled}
onSelectRow={() => selectRow(item, index)}
showTooltip={showTooltip}
/>
);
};
Expand Down
66 changes: 43 additions & 23 deletions src/components/SelectionList/CheckboxListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,39 @@ import * as StyleUtils from '../../styles/StyleUtils';
import Icon from '../Icon';
import * as Expensicons from '../Icon/Expensicons';
import themeColors from '../../styles/themes/default';
import Tooltip from '../Tooltip';
import UserDetailsTooltip from '../UserDetailsTooltip';

function CheckboxListItem({item, isFocused = false, onSelectRow, onDismissError = () => {}}) {
function CheckboxListItem({item, isFocused = false, showTooltip = false, onSelectRow, onDismissError = () => {}}) {
const hasError = !_.isEmpty(item.errors);

const avatar = (
<Avatar
containerStyles={styles.pl5}
source={lodashGet(item, 'avatar.source', '')}
name={lodashGet(item, 'avatar.name', item.text)}
type={lodashGet(item, 'avatar.type', CONST.ICON_TYPE_AVATAR)}
/>
);

const text = (
<Text
style={[styles.optionDisplayName, isFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText, styles.sidebarLinkTextBold]}
numberOfLines={1}
>
{item.text}
</Text>
);

const alternateText = (
<Text
style={[isFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText, styles.optionAlternateText, styles.textLabelSupporting]}
numberOfLines={1}
>
{item.alternateText}
</Text>
);

return (
<OfflineWithFeedback
onClose={() => onDismissError(item)}
Expand Down Expand Up @@ -53,29 +82,20 @@ function CheckboxListItem({item, isFocused = false, onSelectRow, onDismissError
/>
)}
</View>
{Boolean(item.avatar) && (
<Avatar
containerStyles={styles.pl5}
source={lodashGet(item, 'avatar.source', '')}
name={lodashGet(item, 'avatar.name', item.text)}
type={lodashGet(item, 'avatar.type', CONST.ICON_TYPE_AVATAR)}
/>
)}
<View style={[styles.flex1, styles.flexColumn, styles.justifyContentCenter, styles.alignItemsStart, styles.pl3, styles.optionRow]}>
<Text
style={[styles.optionDisplayName, isFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText, styles.sidebarLinkTextBold]}
numberOfLines={1}
>
{item.text}
</Text>
{Boolean(item.alternateText) && (
<Text
style={[isFocused ? styles.sidebarLinkActiveText : styles.sidebarLinkText, styles.optionAlternateText, styles.textLabelSupporting]}
numberOfLines={1}
{Boolean(item.avatar) &&
(showTooltip ? (
<UserDetailsTooltip
accountID={item.accountID}
shiftHorizontal={styles.pl5.paddingLeft / 2}
>
thiagobrez marked this conversation as resolved.
Show resolved Hide resolved
{item.alternateText}
</Text>
)}
<View>{avatar}</View>
</UserDetailsTooltip>
) : (
avatar
))}
<View style={[styles.flex1, styles.flexColumn, styles.justifyContentCenter, styles.alignItemsStart, styles.pl3, styles.optionRow]}>
{showTooltip ? <Tooltip text={item.text}>{text}</Tooltip> : text}
{Boolean(item.alternateText) && (showTooltip ? <Tooltip text={item.alternateText}>{alternateText}</Tooltip> : alternateText)}
</View>
{Boolean(item.rightElement) && item.rightElement}
</PressableWithFeedback>
Expand Down
3 changes: 3 additions & 0 deletions src/components/SelectionList/selectionListPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ const checkboxListItemPropTypes = {
/** Whether this item is focused (for arrow key controls) */
isFocused: PropTypes.bool,

/** Whether this item should show Tooltip */
showTooltip: PropTypes.bool,

/** Callback to fire when the item is pressed */
onSelectRow: PropTypes.func.isRequired,

Expand Down
1 change: 1 addition & 0 deletions src/pages/workspace/WorkspaceMembersPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ function WorkspaceMembersPage(props) {

result.push({
keyForList: accountID,
accountID: Number(accountID),
isSelected: _.contains(selectedEmployees, Number(accountID)),
isDisabled: accountID === props.session.accountID || details.login === props.policy.owner || policyMember.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
text: props.formatPhoneNumber(details.displayName),
Expand Down