Skip to content

feat(Alert): add maxHeight with show more toggle - #1279

Open
fneves wants to merge 12 commits into
mainfrom
fn/cui-336-alert-max-height-0fd0
Open

fneves wants to merge 12 commits into
mainfrom
fn/cui-336-alert-max-height-0fd0

Conversation

@fneves

@fneves fneves commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Description

A long error in an alert pushes the page under it. Query failures are the usual case: the message is many lines, and the reader still needs all of it.

#1277 made those line breaks visible. The review on that PR asked for the next step on the same component: cap the alert, and let the reader open the rest in place. Each app should not have to build its own Show more box.

This is that follow-up (CUI-336). Alert is unchanged until you pass maxHeight.

  • Collapsed: the alert stays within the height you set, so the layout around it does not move. Overflowing text fades at the bottom and offers Show more.
  • Expanded: the alert uses the width and height the parent already has, so the reader can read the rest there. If the message is still taller than that space, it scrolls inside the alert. Show less returns to the short height.
  • Why not a new component: feat(Alert): add preserveLineBreaks prop #1277 also considered a dedicated error component. This PR keeps the behavior on Alert, because the need is a long message in an alert. Happy to revisit that.

maxHeight is a number (px) or any CSS length ('12lh', '100%'). The cap includes the toggle. onExpandedChange fires only when maxHeight is set. expandLabel and collapseLabel default to Show more and Show less. WarningAlert, DangerAlert, InfoAlert, and SuccessAlert pass the props through.

<WarningAlert title="Query failed" text={error.message} preserveLineBreaks maxHeight={240} />
<WarningAlert key={run.id} text={error.message} maxHeight="100%" onExpandedChange={track} />

The expanded state stays inside the alert. Remount with key to reset it. There is no controlled expanded prop, and the text does not open in a modal.

Links and tickets

Checklist

  • Breaking changes? (add migration notes in changesets) — no. The changeset is minor.
  • Visual changes? (specify in changesets) — only when maxHeight is set. Collapsed snapshots are unchanged. The four expanded snapshots were regenerated because the expanded alert now fills its container.
  • Design review needed? — yes, for the text-style toggle and the labels.

Contribution

  • Sufficient research before PR
  • Self-reviewed the PR
  • Manually tested the changes (when applies - visual confirmation in Storybook)
  • build and build-storybook work locally
  • Tests and Stories are aligned with the changes

Accessibility

  • Keyboard — the toggle is a native <button> (Enter / Space), and focus stays on it after both actions. While expanded and scrollable, the text area is focusable, so arrow keys scroll it. Tabbing onto a link inside clipped text expands the alert. Esc doesn't apply.
  • Names — the toggle's visible label is its accessible name, with aria-expanded and aria-controls. When a title exists, the scroll region is role="region", named by the title.
  • Vision — the toggle inherits the alert text colour, and its focus ring uses --click-global-color-outline-default. The fade is removed in forced-colors mode. The text toggle is under 24 px tall and relies on the WCAG 2.5.8 spacing exception (it sits alone on its row).

WCAG 2.2 criteria checked: 1.4.3 Contrast (the toggle inherits the alert text colour), 2.1.1 Keyboard, 2.4.3 Focus Order, 2.4.7 Focus Visible, 2.5.3 Label in Name, 4.1.2 Name, Role, Value. In the Storybook Accessibility panel, axe shows no new violations on the new stories. The existing colour-contrast findings on info-state alerts also appear on the current StateInfo story. Not tested with a real screen reader.

Screencast

Collapsed, the alert stays short. Expanded, it uses the space the parent already has and the message scrolls. Show less returns to the short height.

alert-scrollbar-at-right-edge.mp4

Open in Web Open in Cursor 

Note

Low Risk
Additive, opt-in API on a display component; existing alerts unchanged. Risk is mainly layout/interaction edge cases around dynamic height and observer lifecycle, mitigated by extensive tests.

Reviewed by Cursor Bugbot for commit 61633ee. Bugbot is set up for automated code reviews on this repo. Configure here.

cursoragent and others added 7 commits October 23, 2026 16:47
Co-authored-by: Fábio Neves <fabio.neves@clickhouse.com>
Co-authored-by: Fábio Neves <fabio.neves@clickhouse.com>
Co-authored-by: Fábio Neves <fabio.neves@clickhouse.com>
Co-authored-by: Fábio Neves <fabio.neves@clickhouse.com>
Co-authored-by: Fábio Neves <fabio.neves@clickhouse.com>
Co-authored-by: Fábio Neves <fabio.neves@clickhouse.com>
…g it

Co-authored-by: Fábio Neves <fabio.neves@clickhouse.com>
@changeset-bot

changeset-bot Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 61633ee

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@clickhouse/click-ui Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

cursoragent and others added 2 commits October 26, 2026 08:55
Collapsed alerts stay capped by maxHeight. Expanded alerts lift that cap,
grow to the parent, and scroll the text when it still overflows.

Co-authored-by: Fábio Neves <fabio.neves@clickhouse.com>
The expanded alert now fills its container, so the expanded captures are taller and show the text scrollbar.

Co-authored-by: Fábio Neves <fabio.neves@clickhouse.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

min-height: 0;
max-height: none;
flex: 1 1 auto;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Expanding drops the height cap

High Severity

Expanding applies alert_expanded, which sets max-height to none. If the parent has no definite height, height: 100% and flex: 1 1 auto do nothing, so the alert grows with the text. Overflow then measures as false, the Show less toggle unmounts, and the expanded layout cannot be collapsed.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ca3b277. Configure here.

@DreaminDani DreaminDani Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yup. You can see it on the top story in this screenshot:

Image

Please fix before merging :)

cursoragent and others added 2 commits November 2, 2026 10:41
The text column was only as wide as the message, so the scrollbar sat in the middle of the alert. It now fills the remaining width.

Co-authored-by: Fábio Neves <fabio.neves@clickhouse.com>
The expanded story play only opens the alert. Height, scroll, and width stay in the Playwright test.

Co-authored-by: Fábio Neves <fabio.neves@clickhouse.com>
@XOP XOP added the enhancement New feature or request label Nov 10, 2026
@workflow-authentication-public

Copy link
Copy Markdown
Contributor

Storybook Preview Deployed

✅ Preview URL: https://click-7mu0xyfyv-clickhouse.vercel.app

Built from commit: 529bded2feffdbfc979e4b94858573a06eb54dfd

@workflow-authentication-public

Copy link
Copy Markdown
Contributor

Chromatic Storybook

Check Status Link
Storybook ✅ 679 stories published Open Storybook
UI Tests ⏳ 9 changes must be accepted as baselines Open build

Built from commit: 61633ee58bb6def8afd2e39345ac005117b9ec45 · Chromatic run

Statuses as of the end of the run. The build link shows the live review state.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 61633ee. Configure here.

>
{isExpanded ? collapseLabel : expandLabel}
</button>
)}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Show less vanishes after expand

High Severity

The Show more control is rendered only while isOverflowing is true, including after expand. Expanding lifts max-height and sets height: 100%, so the text often fits in the new layout. The toggle then unmounts, Show less is gone, and keyboard focus on that button is dropped. For the common maxHeight={240} usage without a sized parent, the alert grows with the message and cannot be collapsed, which brings back the layout jump this feature is meant to prevent.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 61633ee. Configure here.

@XOP XOP left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please consider the updates.

}

/* Expanded lifts the collapsed cap and fills the parent. The text then scrolls. */
.alert_max-height.alert_expanded {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we instead go with max-height: 100% instead of height: 100%; flex: 1 1 auto while expanded?

what happens - after Show more activation, the alert grows until nothing overflows, so the toggle unmounts in the same click and focus falls to body.

Note that test would also require changes.

}

/* stylelint-disable plugin/no-unsupported-browser-features, property-no-vendor-prefix -- Chrome below 120 and Safari below 15.4 only know the prefixed mask, and the build has no autoprefixer */
.alert_max-height .alert__text {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Image

the focus ring is "cut" by the gradient,
what can help is removing the mask on :focus-within and adding outline on .alert__text:focus-visible

ref={textRef}
id={hasMaxHeight ? textId : undefined}
tabIndex={isScrollable ? 0 : undefined}
role={isScrollable && hasTitle ? 'region' : undefined}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Without a title the expanded text gets tabIndex=0 but no role or name.
Could it always be role="region", named by the title or by a fallback label when there is none?

/** When true, string `text` keeps `\n` line breaks. Defaults to `false`. */
preserveLineBreaks?: boolean;
/** Caps the collapsed alert, toggle included. Expanded, the cap lifts and the alert fills its container; the text scrolls if it still overflows. A number is px; a string is any CSS length, e.g. `'12lh'` or `'100%'`. */
maxHeight?: number | string;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Every other maxHeight / maxWidth in the library is string only. Can this be string too?

@XOP
XOP requested a review from DreaminDani November 10, 2026 14:33

const rootStyle = useMemo(
() =>
hasMaxHeight

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we need a reasonable lower bound on maxHeight. Otherwise, we'll end up with some weird collapsed states:

CleanShot.2026-11-10.at.08.45.18.mp4

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

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants