@elastic/eslint-plugin-eui
This package contains an eslint plugin that enforces some default rules for using EUI.
Setup
- Install
@elastic/eslint-plugin-eui as a dev dependency.
- Extend
plugin:@elastic/eui/recommended in your ESLint config.
Rules
@elastic/eui/href-or-on-click
<EuiButton /> should either be a button or a link, for a11y purposes. When given an href the button behaves as a link, otherwise an onClick handler is expected and it will behave as a button.
@elastic/eui/href-or-on-click
<EuiButton /> should either be a button or a link, for a11y purposes. When given an href the button behaves as a link, otherwise an onClick handler is expected and it will behave as a button.
In some cases it makes sense to disable this rule locally, such as when cmd + click should open the link in a new tab, but a standard click should use the history.pushState() API to change the URL without triggering a full page load.
Exception: EuiLink has to be provided with both onClick and href so that it renders as an anchor and support Ctrl/Cmd+Click to open in a new tab, and other standard link interactions. See @elastic/eui/require-href-for-link.
@elastic/eui/no-restricted-eui-imports
At times, we deprecate features that may need more highlighting and/or that are not possible to annotate with JSDoc @deprecated, e.g. JSON token imports: @elastic/eui/dist/eui_theme_*.json (for context: https://github.com/elastic/kibana/issues/199715#json-tokens).
We don't use no-restricted-imports because ESLint doesn't allow multiple error levels at once and it may conflict with the consumer's existing ESLint configuration for that rule. We need to assure that our rule will produce a warning (as a recommendation).
All deprecations still must follow our deprecation process.
@elastic/eui/no-deprecated-icon-aliases
Disallows deprecated EUI icon aliases that still render. It automatically
replaces them with their supported icon handles.
The rule checks static icon names, including both branches of ? : and the
operands of &&, ||, and ??, in:
- JSX props ending in
IconType on any component, so wrappers that forward
them to EUI are covered
- the
type prop on EuiIcon and EuiIconTip, and component-specific icon
props such as timelineAvatar, icon, logo, iconLeft, and iconRight on
components imported from @elastic/eui
iconType keys in object literals, such as context menu items and table
actions. Other keys, like icon or triggerIconType, are skipped because they
often hold non-EUI values.
See the full table of icon replacements here: https://github.com/elastic/eui/issues/9561
@elastic/eui/no-removed-icons
Disallows icon names that were removed from EUI. EuiIcon treats an unknown
name as an image URL, so a removed name renders as a broken image without a
console error. It checks the same props as
@elastic/eui/no-deprecated-icon-aliases and automatically replaces removed
names with their supported icon handles.
It's a separate rule so it can be an error while deprecated aliases stay
warnings.
@elastic/eui/no-css-color
This rule warns engineers to not use literal css color in the codebase, particularly for CSS properties that apply color to either the html element or text nodes, but rather urge users to defer to using the color tokens provided by EUI.
This rule kicks in on the following JSXAttributes; style, className and css and supports various approaches to providing styling declarations.
Example
The following code:
// Filename: /x-pack/plugins/observability_solution/observability/public/my_component.tsx
import React from 'react';
import { EuiText } from '@elastic/eui';
function MyComponent() {
return (
<EuiText style={{ color: 'red' }}>You know, for search</EuiText>
)
}
// Filename: /x-pack/plugins/observability_solution/observability/public/my_component.tsx
import React from 'react';
import { EuiText } from '@elastic/eui';
function MyComponent() {
const style = {
color: 'red'
}
return (
<EuiText style={{ color: style.color }}>You know, for search</EuiText>
)
}
// Filename: /x-pack/plugins/observability_solution/observability/public/my_component.tsx
import React from 'react';
import { EuiText } from '@elastic/eui';
function MyComponent() {
const colorValue = '#dd4040';
return (
<EuiText style={{ color: colorValue }}>You know, for search</EuiText>
)
}
will all raise an eslint report with an appropriate message of severity that matches the configuration of the rule, further more all the examples above
will also match for when the attribute in question is css. The css attribute will also raise a report the following cases below;
// Filename: /x-pack/plugins/observability_solution/observability/public/my_component.tsx
import React from 'react';
import { css } from '@emotion/css';
import { EuiText } from '@elastic/eui';
function MyComponent() {
return (
<EuiText css={css`color: '#dd4040' `}>You know, for search</EuiText>
)
}
// Filename: /x-pack/plugins/observability_solution/observability/public/my_component.tsx
import React from 'react';
import { EuiText } from '@elastic/eui';
function MyComponent() {
return (
<EuiText css={() => ({ color: '#dd4040' })}>You know, for search</EuiText>
)
}
A special case is also covered for the className attribute, where the rule will also raise a report for the following case below;
// Filename: /x-pack/plugins/observability_solution/observability/public/my_component.tsx
import React from 'react';
import { css } from '@emotion/css';
import { EuiText } from '@elastic/eui';
function MyComponent() {
return (
<EuiText className={css`color: '#dd4040'`}>You know, for search</EuiText>
)
}
It's worth pointing out that although the examples provided are specific to EUI components, this rule applies to all JSX elements.
@elastic/eui/require-aria-label-for-modals
Ensure that EUI modal components (EuiModal, EuiFlyout, EuiFlyoutResizable ,EuiConfirmModal, EuiPopover, EuiWrappingPopover) have either an aria-label or aria-labelledby prop for accessibility. This helps screen reader users understand the purpose and content of modal dialogs.
@elastic/eui/consistent-is-invalid-props
Ensure that form control components within EuiFormRow components have matching isInvalid prop values. This maintains consistent validation state between parent form rows and their child form controls, leading to a more predictable and accessible user experience.
@elastic/eui/sr-output-disabled-tooltip
Ensure disableScreenReaderOutput is set when EuiToolTip content matches EuiButtonIcon "aria-label".
@elastic/eui/prefer-eui-icon-tip
Ensure EuiIconTip is used rather than <EuiToolTip><EuiIcon/></EuiToolTip>, as it provides better accessibility and improved support for assistive technologies.
@elastic/eui/no-unnamed-radio-group
Ensure that all radio input components (EuiRadio, EuiRadioGroup) have a name attribute. The name attribute is required for radio inputs to be grouped correctly, allowing users to select only one option from a set. Without a name, radios may not behave as expected and can cause accessibility issues for assistive technologies.
@elastic/eui/callout-announce-on-mount
Ensure that EuiCallOut components rendered conditionally have the announceOnMount prop for better accessibility. When callouts appear dynamically (e.g., after user interactions, form validation errors, or status changes), screen readers may not announce their content to users. The announceOnMount prop ensures these messages are properly announced to users with assistive technologies.
@elastic/eui/callout-prefer-props-for-content
Enforce correct usage of EuiCallOut text and actionProps props and discourage using children for content.
EuiCallOut accepts dedicated text and actionProps props introduced to standardize callout content:
- Text content (plain text,
<p>, <span>, <strong>, etc. or EUI text components like EuiText) should be passed via the text prop.
- Action elements (buttons and non-inline links) should be passed via
actionProps, which renders standardized primary and secondary action buttons.
The rule warns (rather than errors) to allow incremental migration from the children pattern.
Examples
// ✗ Flagged — text content via children
<EuiCallOut title="Title">
<p>Callout body text.</p>
</EuiCallOut>
// ✓ Good
<EuiCallOut title="Title" text={<p>Callout body text.</p>} />
// ✗ Flagged — action button via children
<EuiCallOut title="Title">
<EuiButton onClick={onClick}>Take action</EuiButton>
</EuiCallOut>
// ✓ Good
<EuiCallOut
title="Title"
actionProps={{ primary: { children: 'Take action', onClick: onClick } }}
/>
The rule traverses fragments (<>, <React.Fragment>, <Fragment>), layout containers (EuiFlexGroup, EuiFlexGrid, EuiFlexItem, div), and conditional/logical expressions. It does not traverse custom component children, since their content cannot be statically analyzed.
Options
| Option |
Type |
Default |
Description |
components |
string[] |
['EuiCallOut'] |
Component names to check. Replaces the default — include 'EuiCallOut' explicitly if you also want to keep checking it. |
// .eslintrc.js
'@elastic/eui/callout-prefer-props-for-content': ['warn', {
components: ['EuiCallOut', 'KbnWarningCallout'],
}]
@elastic/eui/no-unnamed-interactive-element
Ensure that appropriate aria-attributes are set for EuiBetaBadge, EuiButtonIcon, EuiComboBox, EuiSelect, EuiSelectWithWidth,EuiSuperSelect,EuiPagination, EuiTreeView, EuiBreadcrumbs. Without this rule, screen reader users lose context, keyboard navigation can be confusing.
@elastic/eui/tooltip-focusable-anchor
Ensure EuiTooltip components are anchored to elements that can receive keyboard focus, making them accessible to all users. When using non-interactive elements (like spanor EuiText) as tooltip anchors, they must include tabIndex={0} to be keyboard-focusable. For better accessibility, prefer using semantic interactive components (like EuiButton or EuiLink) which are focusable by default.
@elastic/eui/accessible-interactive-element
Ensure interactive EUI components (like e.g. EuiLink, EuiButton, EuiRadio) remain accessible by prohibiting tabIndex={-1}, which removes them from keyboard navigation.
@elastic/eui/require-table-caption
Ensure EuiInMemoryTable, EuiBasicTable have a tableCaption property for accessibility.
@elastic/eui/badge-accessibility-rules
Ensure the EuiBadge includes appropriate accessibility attributes.
iconOnClick and onClick must not reference the same callback. The rule autofixes by removing iconOnClick.
iconOnClickAriaLabel is only valid when iconOnClick is present. The rule autofixes by removing iconOnClickAriaLabel.
onClickAriaLabel is only valid when onClick is present. The rule autofixes by removing onClickAriaLabel.
@elastic/eui/require-href-for-link
Ensure EuiLink components that have an onClick handler also include an href prop. Without href, the component does not render as a true link, which means users cannot Ctrl/Cmd+Click to open in a new tab or use other standard link interactions. The rule bails out when spread attributes are present, since href may be provided via the spread.
@elastic/eui/icon-accessibility-rules
Ensure the EuiIcon includes appropriate accessibility attributes.
EuiIcon has an accessible name via title, aria-label, or aria-labelledby; otherwise mark it decorative with aria-hidden={true}
- Do not combine
tabIndex with aria-hidden
@elastic/eui/tooltip-button-icon-wrap
Ensure EuiButtonIcon is wrapped with EuiToolTip for sighted users.
Browser-native tooltips (the title prop) are unstyled, have no delay control, and are not keyboard-accessible. Every icon button should have a visible tooltip so that sighted users who do not rely on screen readers can understand its purpose.
The rule reports two situations:
title prop is present - remove it and use <EuiToolTip content={…}> instead.
- No
EuiToolTip wrapper - the button icon has no visible tooltip. Wrap it with <EuiToolTip content={ariaLabel}>.
Buttons with spread props ({...props}) are intentionally skipped when no title prop is explicitly present because their final prop set cannot be statically determined.
Exception: an EuiButtonIcon rendered as the render-prop child of an EuiCopy that sets a non-empty beforeMessage is not flagged for a missing wrapper. EuiCopy wraps its child in an EuiToolTip using beforeMessage as the content, so adding another EuiToolTip would create nested, conflicting tooltips — see @elastic/eui/no-nested-copy-tooltip. This exception is conditional: because EuiToolTip suppresses itself when its content is empty, an EuiButtonIcon inside an EuiCopy with a missing or statically empty/falsy beforeMessage (e.g. "", {null}, {undefined}, {false}) has no visible tooltip and is still reported. A button passed through the beforeMessage prop itself (rather than the render-prop child) is also still reported, since it is not the element EuiCopy's tooltip wraps. A title prop is always reported in this case, since browser-native tooltips remain discouraged.
Examples
// ✗ Bad - browser tooltip
<EuiButtonIcon title="Edit item" aria-label="Edit item" iconType="pencil" />
// ✓ Good
<EuiToolTip content="Edit item">
<EuiButtonIcon aria-label="Edit item" iconType="pencil" />
</EuiToolTip>
// ✓ Good - EuiCopy provides the tooltip via `beforeMessage`, no wrapper needed
<EuiCopy textToCopy="some text" beforeMessage="Copy me">
{(copy) => <EuiButtonIcon onClick={copy} aria-label="Copy" iconType="copy" />}
</EuiCopy>
// ✗ Bad - no tooltip for sighted users
<EuiButtonIcon aria-label="Delete" iconType="trash" />
// ✓ Good
<EuiToolTip content="Delete">
<EuiButtonIcon aria-label="Delete" iconType="trash" />
</EuiToolTip>
@elastic/eui/tooltip-no-interactive-content
Disallow interactive elements inside EuiToolTip and EuiIconTip content and title props.
Tooltip content is rendered in a portal with role="tooltip". It is shown only on hover or focus of the trigger element and is not itself reachable by keyboard. Placing interactive elements (links, buttons, inputs, etc.) inside tooltip content makes them inaccessible to keyboard and screen-reader users. Use EuiPopover for content that requires interaction.
The rule checks both the content and title props of EuiToolTip and EuiIconTip for the following elements: a, button, input, select, textarea, EuiLink, EuiButton, EuiButtonEmpty, EuiButtonIcon, and other interactive EUI components.
Variable content (e.g. content={tooltipContent}) cannot be statically analyzed and is intentionally skipped.
Examples
// ✗ Bad - link inside tooltip is not keyboard-reachable
<EuiToolTip content={<EuiLink href="/docs">Learn more</EuiLink>}>
<EuiButton>Hover me</EuiButton>
</EuiToolTip>
// ✓ Use `EuiPopover` for interactive content
<EuiPopover button={<EuiButton>Click me</EuiButton>} ...>
<EuiLink href="/docs">Learn more</EuiLink>
</EuiPopover>
// ✗ Bad - button inside `EuiIconTip` content
<EuiIconTip content={<EuiButton>Click</EuiButton>} type="info" />
// ✓ Use plain text or non-interactive JSX
<EuiIconTip content="Informational text" type="info" />
@elastic/eui/prefer-tooltip-trigger-focus-test-utility