Skip to content

fix(ui-elements): center tooltip alignment, add text crash guard, and fix ActionButton icon overflow - #1399

Open
Diwaspant132 wants to merge 1 commit into
RocketChat:developfrom
Diwaspant132:fix/tooltip-actionbutton-ui-alignment
Open

Diwaspant132 wants to merge 1 commit into
RocketChat:developfrom
Diwaspant132:fix/tooltip-actionbutton-ui-alignment

Conversation

@Diwaspant132

Copy link
Copy Markdown

fix(ui-elements): center tooltip alignment, add text crash guard, and fix ActionButton icon overflow

Description

This pull request addresses several UI alignment, reliability, and accessibility defects across @embeddedchat/ui-elements:

  1. Tooltip Centering (left: 50%): In Tooltip.styles.js, tooltips previously used a hardcoded left: 64%; transform: translateX(-50%), causing every tooltip in the chat interface to be skewed ~14% off-center to the right of its anchor button. Changed to left: 50%; transform: translateX(-50%) to ensure exact centering.
  2. Defensive Text Guard & Crash Prevention: Tooltip.js previously executed {text.charAt(0).toUpperCase() + text.slice(1)} without verifying that text was a defined non-empty string. Hovering over elements without a title (e.g. attachments with falsy attachment?.title) threw an unhandled TypeError: Cannot read properties of undefined (reading 'charAt'). Added safe string handling and only render the tooltip popup when hasText is true.
  3. Timer Memory Leak Fix: Replaced functional-component-scoped let touchTimer with useRef and added unmount cleanup in useEffect.
  4. Keyboard Accessibility (a11y): Added onFocus, onBlur, and Escape key dismissal handlers along with role="tooltip" and aria-hidden attributes so keyboard users navigating with Tab can access tooltips.
  5. Arrow Normalization on "down": Handled both position="bottom" and position="down" variants so arrows invert (rotate(180deg)) and anchor properly when "down" is passed (e.g. in AttachmentMetadata.js).
  6. ActionButton Small/Large Icon Sizing: When size="small" was passed to ActionButton (a 20px / 1.25rem square button), icons defaulted to 24px (1.5rem), overflowing outside the button bounds. Added getIconSize helper that derives appropriate icon sizing based on button size (small -> 1rem, large -> 1.75rem, medium -> 1.25rem) while supporting explicit string and object overrides.

Acceptance Criteria fulfillment

  • Tooltip container is centered over anchor elements (left: 50%).
  • Tooltip safely handles undefined, null, and empty strings without runtime errors.
  • Keyboard focus (onFocus / onBlur) and Escape key dismissal supported.
  • role="tooltip" and aria-hidden attributes added.
  • size="small" ActionButton displays properly scaled 1rem icon without container overflow.
  • 19 unit tests added and passing.
  • Prettier and ESLint pass without warnings or errors.

PR Test Details

  • Run unit test suites: node --test packages/ui-elements/src/components/**/*.test.mjs (19/19 passing).
  • Run formatting check: yarn format:check (10/10 projects passed).
  • Verify in Storybook: cd packages/ui-elements && yarn storybook -> Components -> Tooltip & ActionButton.

… fix ActionButton icon overflow

Signed-off-by: Diwaspant132 <diwaspanta132@gmail.com>
@Diwaspant132
Diwaspant132 force-pushed the fix/tooltip-actionbutton-ui-alignment branch from 663f90f to e3f1d41 Compare October 23, 2026 15:55

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant