Skip to content

Commit 86a7c90

Browse files
authored
Merge pull request #55216 from Shahidullah-Muffakir/fix/55032
Add tooltip for the inactive tab in the create expense page when the tab title is hidden
2 parents 2a2ea65 + 831a941 commit 86a7c90

2 files changed

Lines changed: 102 additions & 19 deletions

File tree

src/components/TabSelector/TabSelectorItem.tsx

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, {useState} from 'react';
22
import {Animated} from 'react-native';
33
import PressableWithFeedback from '@components/Pressable/PressableWithFeedback';
4+
import Tooltip from '@components/Tooltip';
45
import useThemeStyles from '@hooks/useThemeStyles';
56
import CONST from '@src/CONST';
67
import type IconAsset from '@src/types/utils/IconAsset';
@@ -49,29 +50,34 @@ function TabSelectorItem({
4950
const [isHovered, setIsHovered] = useState(false);
5051

5152
return (
52-
<AnimatedPressableWithFeedback
53-
accessibilityLabel={title}
54-
style={[styles.tabSelectorButton, styles.tabBackground(isHovered, isActive, backgroundColor), styles.userSelectNone]}
55-
wrapperStyle={[styles.flexGrow1]}
56-
onPress={onPress}
57-
onHoverIn={() => setIsHovered(true)}
58-
onHoverOut={() => setIsHovered(false)}
59-
role={CONST.ROLE.BUTTON}
60-
dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: true}}
53+
<Tooltip
54+
shouldRender={!shouldShowLabelWhenInactive && !isActive}
55+
text={title}
6156
>
62-
<TabIcon
63-
icon={icon}
64-
activeOpacity={styles.tabOpacity(isHovered, isActive, activeOpacity, inactiveOpacity).opacity}
65-
inactiveOpacity={styles.tabOpacity(isHovered, isActive, inactiveOpacity, activeOpacity).opacity}
66-
/>
67-
{(shouldShowLabelWhenInactive || isActive) && (
68-
<TabLabel
69-
title={title}
57+
<AnimatedPressableWithFeedback
58+
accessibilityLabel={title}
59+
style={[styles.tabSelectorButton, styles.tabBackground(isHovered, isActive, backgroundColor), styles.userSelectNone]}
60+
wrapperStyle={[styles.flexGrow1]}
61+
onPress={onPress}
62+
onHoverIn={() => setIsHovered(true)}
63+
onHoverOut={() => setIsHovered(false)}
64+
role={CONST.ROLE.BUTTON}
65+
dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: true}}
66+
>
67+
<TabIcon
68+
icon={icon}
7069
activeOpacity={styles.tabOpacity(isHovered, isActive, activeOpacity, inactiveOpacity).opacity}
7170
inactiveOpacity={styles.tabOpacity(isHovered, isActive, inactiveOpacity, activeOpacity).opacity}
7271
/>
73-
)}
74-
</AnimatedPressableWithFeedback>
72+
{(shouldShowLabelWhenInactive || isActive) && (
73+
<TabLabel
74+
title={title}
75+
activeOpacity={styles.tabOpacity(isHovered, isActive, activeOpacity, inactiveOpacity).opacity}
76+
inactiveOpacity={styles.tabOpacity(isHovered, isActive, inactiveOpacity, activeOpacity).opacity}
77+
/>
78+
)}
79+
</AnimatedPressableWithFeedback>
80+
</Tooltip>
7581
);
7682
}
7783

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import {render} from '@testing-library/react-native';
2+
import React from 'react';
3+
import TabSelectorItem from '@components/TabSelector/TabSelectorItem';
4+
import Tooltip from '@components/Tooltip';
5+
6+
// Mock the Tooltip component since it uses portals which aren't supported in RNTL
7+
jest.mock('@components/Tooltip');
8+
9+
describe('TabSelectorItem Component', () => {
10+
const title = 'Test Tab';
11+
12+
beforeEach(() => {
13+
jest.clearAllMocks();
14+
});
15+
16+
it('should show tooltip for inactive tab with hidden label', () => {
17+
// Given an inactive tab with a hidden label
18+
render(
19+
<TabSelectorItem
20+
title={title}
21+
shouldShowLabelWhenInactive={false}
22+
isActive={false}
23+
/>,
24+
);
25+
26+
// Then the tooltip should be rendered with correct content because the label is hidden
27+
expect(Tooltip).toHaveBeenCalledWith(
28+
expect.objectContaining({
29+
shouldRender: true,
30+
text: title,
31+
}),
32+
expect.any(Object),
33+
);
34+
});
35+
36+
it('should not show tooltip for active tab', () => {
37+
// Given an active tab
38+
render(
39+
<TabSelectorItem
40+
title={title}
41+
shouldShowLabelWhenInactive={false}
42+
isActive
43+
/>,
44+
);
45+
46+
// When hovering over the tab button
47+
// Then the tooltip should not render because the tab is active
48+
expect(Tooltip).toHaveBeenCalledWith(
49+
expect.objectContaining({
50+
shouldRender: false,
51+
text: title,
52+
}),
53+
expect.any(Object),
54+
);
55+
});
56+
57+
it('should not show tooltip when label is visible', () => {
58+
// Given an inactive tab with visible label
59+
render(
60+
<TabSelectorItem
61+
title={title}
62+
shouldShowLabelWhenInactive
63+
isActive={false}
64+
/>,
65+
);
66+
67+
// When hovering over the tab button
68+
// Then the tooltip should not render because the label is already visible
69+
expect(Tooltip).toHaveBeenCalledWith(
70+
expect.objectContaining({
71+
shouldRender: false,
72+
text: title,
73+
}),
74+
expect.any(Object),
75+
);
76+
});
77+
});

0 commit comments

Comments
 (0)