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(MenuItem): tooltip should on all item and not only on title #1914

1 change: 1 addition & 0 deletions src/components/Menu/Menu/Menu.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.menu {
margin: unset;
padding: unset;
position: relative;
talkor marked this conversation as resolved.
Show resolved Hide resolved
}

.menu:focus {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ exports[`Snapshots renders correctly with children 1`] = `
>
item 1
</div>
<div
aria-hidden={true}
className="hiddenTitle"
tabIndex={-1}
>
item 1
</div>

<div
style={
Expand All @@ -64,6 +71,13 @@ exports[`Snapshots renders correctly with children 1`] = `
>
item 2
</div>
<div
aria-hidden={true}
className="hiddenTitle"
tabIndex={-1}
>
item 2
</div>

<div
style={
Expand Down
7 changes: 7 additions & 0 deletions src/components/Menu/MenuItem/MenuItem.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,10 @@
flex-grow: 1;
padding-block: 1px;
}

.hiddenTitle {
width: 100%;
position: absolute;
left: 0;
opacity: 0;
}
6 changes: 4 additions & 2 deletions src/components/Menu/MenuItem/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,15 @@ const MenuItem: VibeComponent<MenuItemProps> & {
content={shouldShowTooltip ? finalTooltipContent : null}
position={tooltipPosition}
showDelay={tooltipShowDelay}
// Tooltip should be on a whole MenuItem, but it's a breaking change - should be fixed in the next major and then this can be removed
moveBy={icon && tooltipPosition === Tooltip.positions.LEFT ? { main: 30 } : undefined}
{...tooltipProps}
>
<div ref={titleRef} className={styles.title}>
{title}
</div>
{/* Tooltip should be on a whole MenuItem, but it's a breaking change (tooltip adds span) - should be fixed in the next major and then this div be removed */}
<div className={styles.hiddenTitle} aria-hidden tabIndex={-1}>
{title}
</div>
</Tooltip>
{label && <Label kind={Label.kinds.LINE} text={label} />}
{renderSubMenuIconIfNeeded()}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Menu/MenuItem/__tests__/MenuItem.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ describe("<MenuItem />", () => {
});

it("should be able to render menu item text", async () => {
const { getByText } = render(<MenuItem title={title} />);
const menuItemElement = getByText(title);
const { getAllByText } = render(<MenuItem title={title} />);
const menuItemElement = getAllByText(title);
await waitFor(() => expect(menuItemElement).toBeTruthy());
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ exports[`Snapshots renders correctly when disabled 1`] = `
>
my item
</div>
<div
aria-hidden={true}
className="hiddenTitle"
tabIndex={-1}
>
my item
</div>

<div
style={
Expand Down Expand Up @@ -42,6 +49,13 @@ exports[`Snapshots renders correctly when selected 1`] = `
>
my item
</div>
<div
aria-hidden={true}
className="hiddenTitle"
tabIndex={-1}
>
my item
</div>

<div
style={
Expand Down Expand Up @@ -70,6 +84,13 @@ exports[`Snapshots renders correctly with a label 1`] = `
>
my item
</div>
<div
aria-hidden={true}
className="hiddenTitle"
tabIndex={-1}
>
my item
</div>
<span
className=""
data-testid="label"
Expand Down Expand Up @@ -112,6 +133,13 @@ exports[`Snapshots renders correctly with custom class name 1`] = `
className="title"
>

</div>
<div
aria-hidden={true}
className="hiddenTitle"
tabIndex={-1}
>

</div>

<div
Expand Down Expand Up @@ -140,6 +168,13 @@ exports[`Snapshots renders correctly with empty props 1`] = `
className="title"
>

</div>
<div
aria-hidden={true}
className="hiddenTitle"
tabIndex={-1}
>

</div>

<div
Expand Down Expand Up @@ -191,6 +226,13 @@ exports[`Snapshots renders correctly with title and SVG icon 1`] = `
>
my item
</div>
<div
aria-hidden={true}
className="hiddenTitle"
tabIndex={-1}
>
my item
</div>

<div
style={
Expand Down Expand Up @@ -231,6 +273,13 @@ exports[`Snapshots renders correctly with title and font icon 1`] = `
>
my item
</div>
<div
aria-hidden={true}
className="hiddenTitle"
tabIndex={-1}
>
my item
</div>

<div
style={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ exports[`SplitButtonMenu renders correctly 1`] = `
>
Test 1
</div>
<div
aria-hidden={true}
className="hiddenTitle"
tabIndex={-1}
>
Test 1
</div>

<div
style={
Expand All @@ -52,6 +59,13 @@ exports[`SplitButtonMenu renders correctly 1`] = `
>
Test 2
</div>
<div
aria-hidden={true}
className="hiddenTitle"
tabIndex={-1}
>
Test 2
</div>

<div
style={
Expand Down
Loading