Skip to content

Conversation

@Mirzaian
Copy link

@Mirzaian Mirzaian commented Nov 3, 2025

Fixes imprecise tooltip positioning in PollListItem

I found a bug. For shorter poll titles, the tooltip was not displayed optimally. This change fixes the imprecise tooltip positioning.

  • Tooltip now appears centered above poll question text
  • Maintains hover trigger across entire poll item area
  • Uses programmatic control for better UX

Checklist

@Mirzaian Mirzaian requested a review from a team as a code owner November 3, 2025 13:33
@Mirzaian Mirzaian requested review from dbkr and florianduros November 3, 2025 13:33
@github-actions github-actions bot added the Z-Community-PR Issue is solved by a community member's PR label Nov 3, 2025
@CLAassistant
Copy link

CLAassistant commented Nov 3, 2025

CLA assistant check
All committers have signed the CLA.

Optimize tooltip positioning to appear centered above poll question text
while maintaining hover trigger across entire poll item area.
@dbkr
Copy link
Member

dbkr commented Nov 3, 2025

Not sure I quite understand the bug here - sounds like it's visual? In which case screenshots might be useful. Also,I'm not sure about the behaviour of opening the tooltip as soon as the cursor enters - normally there's a delay and this is handled automatically.

@Mirzaian
Copy link
Author

Mirzaian commented Nov 3, 2025

Hey! Yes, its a visual UI issue. The tooltip was previously manually controlled and always appeared in a fixed position, which looked off for shorter poll titles. I have attached current/incoming screenshots to show the difference. The Tooltip now wraps the entire poll item, automatically centers above the title, and the whole item remains clickable.

Regarding the hover delay, I have kept the default timing behavior.
The fix only adjusts the positioning logic for a better UX.

Incoming(current develop) behavior
Bildschirmfoto 2025-11-03 um 17 31 01
Bildschirmfoto 2025-11-03 um 17 33 39

current(my changes) behavior
Bildschirmfoto 2025-11-03 um 17 33 30
Bildschirmfoto 2025-11-03 um 17 33 39

@t3chguy
Copy link
Member

t3chguy commented Nov 3, 2025

It could likely also be fixed with css width: max-width on the parent element or something similar so that it ignores the fill space

@Mirzaian
Copy link
Author

Mirzaian commented Nov 3, 2025

It could likely also be fixed with css width: max-width on the parent element or something similar so that it ignores the fill space

Good point, but I think that max-width approach could technically work as quick fix, but it would introduce responsiveness issues that make my current solution preferable. The decision is up to you guys. This just bothered me quite a bit, hence the PR.

@dbkr
Copy link
Member

dbkr commented Nov 5, 2025

As sonarcloud says, the new code here will need a test.

Comment on lines 59 to 60
expect(contentDiv).toBeTruthy();
expect(questionSpan?.textContent).toBe("Question?");
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure it's really relevant to this test to assert these things, or why we need the question div at all. We also really ought to be selecting things by role, or testId if that really isn't possible. In this case, this raises the question of why the inner div is necessary now that the tooltip is on something inside it: then we could just have the mouseenter/leave be on the li and select it using getByRole("listitem", { name: "01/01/70 Question?" }).

Copy link
Author

@Mirzaian Mirzaian Nov 6, 2025

Choose a reason for hiding this comment

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

Oki, I moved the mouse events to the li element and added the aria-label. I also added getByRole as you suggested.

fireEvent.mouseLeave(contentDiv!);

// Component should still be functional after state changes
expect(container.querySelector(".mx_PollListItem")).toBeTruthy();
Copy link
Member

Choose a reason for hiding this comment

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

I think the test really needs to assert that the tooltip actually appears.

Copy link
Author

Choose a reason for hiding this comment

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

Oki, I replaced the querySelector approach with proper tooltip text assertion.


// Test that mouse events work without error
fireEvent.mouseEnter(contentDiv!);
fireEvent.mouseLeave(contentDiv!);
Copy link
Member

Choose a reason for hiding this comment

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

I realise the rest of the test doesn't, so not a blocker, but new code probably ought to use user-event.

Copy link
Member

@dbkr dbkr left a comment

Choose a reason for hiding this comment

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

Also needs another snapshot update I think


// Verify tooltip content is present
const tooltip = getByText("View poll");
expect(tooltip).toBeInTheDocument();
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this not be in the document at this point? Or at least not be visible? And shouldn't we be testing that's visible when hovering and then disappears again?

Copy link
Author

Choose a reason for hiding this comment

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

I have updated it now and aligned it with the approach used in infotooltip-test.tsx

@Mirzaian Mirzaian requested a review from dbkr November 7, 2025 21:07
Comment on lines +59 to +69
await userEvent.hover(listItem);

// Wait for the tooltip to open
const questionSpan = getByText("Question?");
const tooltip = await waitFor(() => {
const tooltip = document.getElementById(questionSpan.getAttribute("aria-labelledby")!);
expect(tooltip).toBeVisible();
return tooltip;
});
expect(tooltip).toHaveTextContent("View poll");
});
Copy link
Member

Choose a reason for hiding this comment

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

I just tested and, annoyingly, it looks like the test you copied from doesn't actually work, in that the assertion that the tooltip is visible passes even without hovering. I think this is because floating-ui hides the tooltip by positioning it offscreen or something. This means this is actually quite difficult to test. Writing a playwright test might be an option, or possibly mocking the tooltip component to remove that from the equation and just assert that it's been passed open=true. Possibly you could test manually for the tooltip position or classes, although this would be quite fragile. Sorry, this seems to be the classic case of pulling one tiny thread and a bunch of stuff unravelling.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-Defect Z-Community-PR Issue is solved by a community member's PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants