Skip to content

[EuiHtmlIdGenerator] Warn when generated ID prefix/suffix contains whitespace - #9868

Merged
alexwizp merged 8 commits into
mainfrom
claude/eui-warn-log-spaces-9ac057
Aug 11, 2026
Merged

alexwizp merged 8 commits into
mainfrom
claude/eui-warn-log-spaces-9ac057

Conversation

@alexwizp

@alexwizp alexwizp commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • What: useGeneratedHtmlId and htmlIdGenerator now log a console.warn when the passed prefix or suffix contains whitespace.

  • Why: Whitespace in an HTML id is invalid, and it silently breaks every attribute that takes a space-separated list of ID references — aria-controls, aria-labelledby, aria-describedby, for. Each "word" is parsed as a separate reference to a non-existent element, so nothing throws and nothing renders differently; it only surfaces in an accessibility audit.

    This just bit Kibana in [Dataset quality] Fix invalid aria-controls on quality issue flyout mitigation accordions kibana#283063, where a localized accordion title was passed as an id prefix and produced a malformed aria-controls. Passing a human-readable or localized string as a prefix is an easy and repeatable mistake, so it's worth catching at the source.

  • How: A single warnOnWhitespace check in html_id_generator.ts. Notes for reviewers:

    • Warning lives in the ID generator rather than in individual components — every EUI component that builds IDs funnels through here, so one check covers EuiAccordion, form controls, EuiComboBox, etc.
    • The check sits inside the existing useMemo, so it only re-runs when prefix/suffix actually change. This hook runs on virtually every EUI render, so an unmemoized regex per render was worth avoiding.
    • It's skipped when conditionalId wins, since prefix/suffix are unused in that case.
    • Duplicated into html_id_generator.testenv.ts (which replaces the real module in test envs and so can't import from it) — deliberately, so that consumer Jest suites also get the warning. That's the highest-value detection point: Kibana's own unit tests would have surfaced the bug above.
    • Scoped to whitespace only, not a general HTML-id validator. Whitespace is the demonstrated real-world failure; a broader validator risks noisy warnings that downstream repos would mute wholesale.
    • Not implementable as an eslint-plugin-eui rule: the offending value in the Kibana case was an i18n lookup resolved at runtime, not a string literal. A lint rule could complement this but not replace it.
    • Drive-by: the [React 18] generates correct IDs test asserted an exact useId counter (prefix:r3:suffix). That counter is shared across the whole test file, so adding tests shifted it. Changed to assert the ID shape via regex.

API Changes

No public API change — warnOnWhitespace is module-private and not re-exported from services/accessibility/index.ts. Behaviour change is limited to an added console warning.

component / parent prop / child change description
useGeneratedHtmlId / htmlIdGenerator prefix / suffix Behavior Now console.warns if the value contains whitespace

Screenshots

N/A — no visual change. Console output when misused:

[EUI] Generated HTML ID: "Increase field mapping limit" contains whitespace, which generates
an invalid HTML id and breaks attributes referencing it, such as `aria-controls` or `for`.
Pass a static identifier instead of a human-readable or localized string.

Impact Assessment

  • 🔴 Breaking changes
  • 💅 Visual changes
  • 🧪 Test impact — Consumer test suites (notably Kibana) will start emitting this warning wherever a whitespace-containing prefix is passed. This is intentional, but any downstream test that asserts "no console warnings" could fail. Worth a Kibana integration run to size how many call sites are affected before merging.
  • 🔧 Hard to integrate

Impact level: 🟡 Moderate — no runtime behavior change, but new console noise in consumer test suites is the thing to check.

Release Readiness

  • Documentation: n/a — internal dev warning, no docs page
  • Figma: n/a
  • Migration guide: n/a — no breaking change; the warning message itself states the fix
  • Adoption plan: n/a — no adoption needed; applies automatically

QA instructions for reviewer

  • Run yarn test-unit src/services/accessibility/html_id_generator.test.tsx — should pass.
  • In any consuming app or Storybook, render a component with a whitespace prefix, e.g. useGeneratedHtmlId({ prefix: 'my title' }).
    • Confirm the warning appears once in the console.
    • Confirm re-rendering the component does not re-log the warning (memoization).
    • Confirm valid prefixes (e.g. myTitle, my-title) log nothing.
    • Confirm generated IDs themselves are unchanged.
  • Ideally: run this against Kibana and report how many warnings appear (see Impact above).

Checklist before marking Ready for Review

  • Filled out all sections above
  • QA: light/dark modes, high contrast, mobile, browsers, keyboard, screen reader — no rendered output changed
  • QA: Tested in Kibana — not yet done, see Impact Assessment
  • QA: docs changes — none
  • Tests: Added Jest coverage for prefix, suffix, valid values, and conditionalId precedence
  • Changelog: Added
  • Breaking changes: n/a

alexwizp and others added 2 commits August 5, 2026 16:37
IDs containing whitespace are invalid HTML and silently break attributes
that take a space-separated list of ID references (`aria-controls`,
`aria-labelledby`, `for`), since each "word" is parsed as a separate
reference to a non-existent element.

Co-Authored-By: Claude Opus 5 <[email protected]>
Co-Authored-By: Claude Opus 5 <[email protected]>
@elastic-vault-github-plugin-prod

Copy link
Copy Markdown
1 visual difference(s) found - expand to review, then click Approve visual changes to update baselines

euidatagrid (1 difference)

StoryBeforeAfterDiff
compact desktop

@elastic-vault-github-plugin-prod

Copy link
Copy Markdown
1 visual difference(s) found - expand to review, then click Approve visual changes to update baselines

euidatagrid (1 difference)

StoryBeforeAfterDiff
compact desktop

@elastic-vault-github-plugin-prod

Copy link
Copy Markdown
1 visual difference(s) found - expand to review, then click Approve visual changes to update baselines

euidatagrid (1 difference)

StoryBeforeAfterDiff
compact desktop

@alexwizp
alexwizp marked this pull request as ready for review August 10, 2026 12:34
@alexwizp
alexwizp requested a review from a team as a code owner August 10, 2026 12:34
Copilot AI lite review requested due to automatic review settings August 10, 2026 12:34

Copilot AI 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.

Pull request overview

Adds a developer-facing warning to the EUI HTML ID generation utilities to catch invalid id values early when prefix/suffix includes whitespace (which can silently break aria-* and for references), plus updates tests/changelog accordingly.

Changes:

  • Added a shared warnOnWhitespace check to htmlIdGenerator and useGeneratedHtmlId to console.warn on whitespace in prefixes/suffixes.
  • Duplicated the warning logic into the *.testenv.ts replacement module so consumer Jest runs also emit the warning.
  • Updated unit tests (including React 18 useId assertion) and added a changelog entry.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
packages/eui/src/services/accessibility/html_id_generator.ts Adds whitespace detection + warning in the real ID generator and hook implementation
packages/eui/src/services/accessibility/html_id_generator.testenv.ts Mirrors the warning in the test-environment replacement module
packages/eui/src/services/accessibility/html_id_generator.test.tsx Adds warning coverage and relaxes the React 18 ID assertion to a shape regex
packages/eui/changelogs/upcoming/9868.md Documents the added warning behavior

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

alexwizp and others added 4 commits August 10, 2026 16:02
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@elastic-vault-github-plugin-prod

Copy link
Copy Markdown
1 visual difference(s) found - expand to review, then click Approve visual changes to update baselines

euidatagrid (1 difference)

StoryBeforeAfterDiff
compact desktop

@weronikaolejniczak weronikaolejniczak added the skip-vrt Skips Visual Regression Testing job in CI (clearly state why you're using it in your PR) label Aug 10, 2026
@weronikaolejniczak
weronikaolejniczak requested a balanced review from Copilot August 10, 2026 14:18
@weronikaolejniczak

Copy link
Copy Markdown
Contributor

buildkite test this

@weronikaolejniczak weronikaolejniczak 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.

LGTM, just one doubt - wouldn't it be better to strip the whitespaces automatically than just show a runtime warning? 🤔

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Suppressed comments (2)

packages/eui/src/services/accessibility/html_id_generator.ts:26

  • HTML’s id restriction and ID-reference-list tokenization apply to ASCII whitespace only. JavaScript \s also matches valid ID characters such as NBSP (U+00A0) and em spaces, so localized values containing them will emit a false warning even though the reference remains a single token. Match HTML ASCII whitespace explicitly.
  if (value && /\s/.test(value)) {

packages/eui/src/services/accessibility/html_id_generator.testenv.ts:18

  • This duplicated check has the same false-positive behavior as the runtime implementation: \s includes non-ASCII spaces that HTML permits in IDs and does not use to split ID-reference lists. Restrict the test-environment warning to HTML ASCII whitespace as well.
  if (value && /\s/.test(value)) {

@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

💚 Build Succeeded

History

@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

💚 Build Succeeded

History

@alexwizp

Copy link
Copy Markdown
Contributor Author

@weronikaolejniczak

LGTM, just one doubt - wouldn't it be better to strip the whitespaces automatically than just show a runtime warning? 🤔

I like ideas of passing a static identifier instead of a human-readable or localized string. Silent replacement also not the best solution.

@weronikaolejniczak weronikaolejniczak 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.

LGTM 🟢 I don't think the warning will solve the whole issue but it's a good start!

@alexwizp
alexwizp merged commit 0b24a86 into main Aug 11, 2026
5 checks passed
@alexwizp
alexwizp deleted the claude/eui-warn-log-spaces-9ac057 branch August 11, 2026 11:24
JoseLuisGJ pushed a commit to JoseLuisGJ/eui that referenced this pull request Aug 12, 2026
…itespace (elastic#9868)

Co-authored-by: Claude Opus 5 <[email protected]>
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
mgadewoll added a commit to elastic/kibana that referenced this pull request Aug 28, 2026
## Dependency updates

`@elastic/eui` - 119.0.0 ⏩ 119.1.0
`@elastic/eui-test-helpers` - 1.3.0 ⏩ 1.4.0

## Changes

- Updated usages of `EuiFilePickerClass` to `EuiFilePickerRef` after the
migration of `EuiFilePicker` from class to function component

## Package updates

### `@elastic/eui`
[v119.1.0](https://github.com/elastic/eui/blob/main/packages/eui/changelogs/CHANGELOG_2026.md)

- Updated `EuiFlyoutMenu` action icon spacing: `leadingActions` and
`trailingActions` icons are now grouped with a consistent gap between
each icon ([#9887](elastic/eui#9887))
- Updated `EuiFlyoutMenu` back button to show a tooltip with the
previous page title (e.g. "Back to Page 1") when history context is
available ([#9887](elastic/eui#9887))
- Added `cursorDefault`, `logIn`, and `routeSplit` glyphs to `EuiIcon`
([#9885](elastic/eui#9885))
- Updated `EuiSplitButton` to apply redesign style changes
([#9865](elastic/eui#9865))
- Added a development warning to `useGeneratedHtmlId` and
`htmlIdGenerator` when the passed `prefix`/`suffix` contains whitespace,
which generates invalid HTML IDs
([#9868](elastic/eui#9868))
- Updated `EuiButtonGroup`:
([#9862](elastic/eui#9862))
- Added `variant="segmented"` which renders the group as visually
connected control group
- Added `showDividers` prop to optionally render dividers between group
children
- Added `layout` prop to optionally render icon button groups vertically
    - Added `wrap` prop to manually control the group wrapping behavior

**Bug fixes**

- Fixed `EuiDataGrid` header cell actions popover not opening when
pressing Enter on a focused actions button
([#9931](elastic/eui#9931))
- Fixed `EuiFilePicker` losing imperative `ref` support when migrated
from class to function component
([#9879](elastic/eui#9879)). Use
`useRef<EuiFilePickerRef>()` where `useRef<EuiFilePickerClass>()` was
previously used. ([#9930](elastic/eui#9930))
- Fixed `EuiSplitButton` having a wrong `inline-size` when
`textProps={false}` is set on an action button that has `iconType`
([#9917](elastic/eui#9917))

### `@elastic/eui-test-helpers`
[v1.4.0](https://github.com/elastic/eui/blob/main/packages/test-helpers/changelogs/CHANGELOG_2026.md)

- Added `EuiSelectableObject` with `options`, `selectOption(label)` and
`search(term)` ([#9908](elastic/eui#9908))

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Hannah Mudge <[email protected]>
dej611 pushed a commit to dej611/kibana that referenced this pull request Aug 31, 2026
## Dependency updates

`@elastic/eui` - 119.0.0 ⏩ 119.1.0
`@elastic/eui-test-helpers` - 1.3.0 ⏩ 1.4.0

## Changes

- Updated usages of `EuiFilePickerClass` to `EuiFilePickerRef` after the
migration of `EuiFilePicker` from class to function component

## Package updates

### `@elastic/eui`
[v119.1.0](https://github.com/elastic/eui/blob/main/packages/eui/changelogs/CHANGELOG_2026.md)

- Updated `EuiFlyoutMenu` action icon spacing: `leadingActions` and
`trailingActions` icons are now grouped with a consistent gap between
each icon ([elastic#9887](elastic/eui#9887))
- Updated `EuiFlyoutMenu` back button to show a tooltip with the
previous page title (e.g. "Back to Page 1") when history context is
available ([elastic#9887](elastic/eui#9887))
- Added `cursorDefault`, `logIn`, and `routeSplit` glyphs to `EuiIcon`
([elastic#9885](elastic/eui#9885))
- Updated `EuiSplitButton` to apply redesign style changes
([elastic#9865](elastic/eui#9865))
- Added a development warning to `useGeneratedHtmlId` and
`htmlIdGenerator` when the passed `prefix`/`suffix` contains whitespace,
which generates invalid HTML IDs
([elastic#9868](elastic/eui#9868))
- Updated `EuiButtonGroup`:
([elastic#9862](elastic/eui#9862))
- Added `variant="segmented"` which renders the group as visually
connected control group
- Added `showDividers` prop to optionally render dividers between group
children
- Added `layout` prop to optionally render icon button groups vertically
    - Added `wrap` prop to manually control the group wrapping behavior

**Bug fixes**

- Fixed `EuiDataGrid` header cell actions popover not opening when
pressing Enter on a focused actions button
([elastic#9931](elastic/eui#9931))
- Fixed `EuiFilePicker` losing imperative `ref` support when migrated
from class to function component
([elastic#9879](elastic/eui#9879)). Use
`useRef<EuiFilePickerRef>()` where `useRef<EuiFilePickerClass>()` was
previously used. ([elastic#9930](elastic/eui#9930))
- Fixed `EuiSplitButton` having a wrong `inline-size` when
`textProps={false}` is set on an action button that has `iconType`
([elastic#9917](elastic/eui#9917))

### `@elastic/eui-test-helpers`
[v1.4.0](https://github.com/elastic/eui/blob/main/packages/test-helpers/changelogs/CHANGELOG_2026.md)

- Added `EuiSelectableObject` with `options`, `selectOption(label)` and
`search(term)` ([elastic#9908](elastic/eui#9908))

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Hannah Mudge <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accessibility skip-vrt Skips Visual Regression Testing job in CI (clearly state why you're using it in your PR)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants