Repository navigation
[EuiHtmlIdGenerator] Warn when generated ID prefix/suffix contains whitespace - #9868
Conversation
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]>
1 visual difference(s) found - expand to review, then click Approve visual changes to update baselineseuidatagrid (1 difference)
|
1 visual difference(s) found - expand to review, then click Approve visual changes to update baselineseuidatagrid (1 difference)
|
1 visual difference(s) found - expand to review, then click Approve visual changes to update baselineseuidatagrid (1 difference)
|
There was a problem hiding this comment.
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
warnOnWhitespacecheck tohtmlIdGeneratoranduseGeneratedHtmlIdtoconsole.warnon whitespace in prefixes/suffixes. - Duplicated the warning logic into the
*.testenv.tsreplacement module so consumer Jest runs also emit the warning. - Updated unit tests (including React 18
useIdassertion) 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.
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]>
Co-Authored-By: Claude Opus 5 <[email protected]>
1 visual difference(s) found - expand to review, then click Approve visual changes to update baselineseuidatagrid (1 difference)
|
|
buildkite test this |
weronikaolejniczak
left a comment
There was a problem hiding this comment.
LGTM, just one doubt - wouldn't it be better to strip the whitespaces automatically than just show a runtime warning? 🤔
There was a problem hiding this comment.
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
idrestriction and ID-reference-list tokenization apply to ASCII whitespace only. JavaScript\salso 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:
\sincludes 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)) {
💚 Build Succeeded
History
|
💚 Build Succeeded
History
|
I like ideas of passing a static identifier instead of a human-readable or localized string. Silent replacement also not the best solution. |
weronikaolejniczak
left a comment
There was a problem hiding this comment.
LGTM 🟢 I don't think the warning will solve the whole issue but it's a good start!
…itespace (elastic#9868) Co-authored-by: Claude Opus 5 <[email protected]> Co-authored-by: Copilot Autofix powered by AI <[email protected]>
## 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]>
## 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]>



Summary
What:
useGeneratedHtmlIdandhtmlIdGeneratornow log aconsole.warnwhen the passedprefixorsuffixcontains whitespace.Why: Whitespace in an HTML
idis 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
warnOnWhitespacecheck inhtml_id_generator.ts. Notes for reviewers:EuiAccordion, form controls,EuiComboBox, etc.useMemo, so it only re-runs whenprefix/suffixactually change. This hook runs on virtually every EUI render, so an unmemoized regex per render was worth avoiding.conditionalIdwins, sinceprefix/suffixare unused in that case.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.eslint-plugin-euirule: 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.[React 18] generates correct IDstest asserted an exactuseIdcounter (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 —
warnOnWhitespaceis module-private and not re-exported fromservices/accessibility/index.ts. Behaviour change is limited to an added console warning.useGeneratedHtmlId/htmlIdGeneratorprefix/suffixconsole.warns if the value contains whitespaceScreenshots
N/A — no visual change. Console output when misused:
Impact Assessment
Impact level: 🟡 Moderate — no runtime behavior change, but new console noise in consumer test suites is the thing to check.
Release Readiness
n/a— internal dev warning, no docs pagen/an/a— no breaking change; the warning message itself states the fixn/a— no adoption needed; applies automaticallyQA instructions for reviewer
yarn test-unit src/services/accessibility/html_id_generator.test.tsx— should pass.useGeneratedHtmlId({ prefix: 'my title' }).myTitle,my-title) log nothing.Checklist before marking Ready for Review
light/dark modes, high contrast, mobile, browsers, keyboard, screen reader— no rendered output changeddocs changes— noneconditionalIdprecedencen/a