Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/eslint-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### New Features

- `use-recommended-components`: Add an `allowUseWithCaution` option that allows `@wordpress/ui` components marked "Use with caution" ([#83536](https://github.com/WordPress/gutenberg/pull/83536)).

## 27.0.0 (2026-09-23)

### Breaking Changes
Expand Down
13 changes: 13 additions & 0 deletions packages/eslint-plugin/docs/rules/use-recommended-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,16 @@ import { unlock } from '../../lock-unlock';

const { SomethingElse } = unlock( componentsPrivateApis );
```

## Options

This rule has an object option:

- `allowUseWithCaution` (default: `false`): allow `@wordpress/ui` components that are marked "Use with caution" in Storybook. These components are ready for use, but their APIs or behavior may still change. Opt in only if you can follow those changes. They are also not advised to be mixed with existing components from `@wordpress/components` in the same interface, because their visual design and behavior can differ.

Examples of **correct** code for this rule with the `{ "allowUseWithCaution": true }` option:

```js
/* eslint @wordpress/use-recommended-components: ["error", { "allowUseWithCaution": true }] */
import { Button, Dialog } from '@wordpress/ui';
```
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ ruleTester.run( 'use-recommended-components', rule, {
// Allowed @wordpress/ui components.
"import { Badge } from '@wordpress/ui';",

// "Use with caution" components are allowed when opted in.
{
code: "import { Button, Dialog } from '@wordpress/ui';",
options: [ { allowUseWithCaution: true } ],
},

// Unlocked private APIs are only checked for denied names.
"import { privateApis } from '@wordpress/components'; import { unlock } from '../../lock-unlock'; const { SomethingElse } = unlock( privateApis );",
`
Expand Down Expand Up @@ -66,6 +72,37 @@ ruleTester.run( 'use-recommended-components', rule, {
},
],
},
// "Use with caution" components are flagged unless opted in.
{
code: "import { Button } from '@wordpress/ui';",
errors: [
{
message:
'`Button` from `@wordpress/ui` is not yet recommended for use in a WordPress environment.',
},
],
},
{
code: "import { Button } from '@wordpress/ui';",
options: [ { allowUseWithCaution: false } ],
errors: [
{
message:
'`Button` from `@wordpress/ui` is not yet recommended for use in a WordPress environment.',
},
],
},
// Opting in to "Use with caution" does not allow other components.
{
code: "import { Button, SomeComponent } from '@wordpress/ui';",
options: [ { allowUseWithCaution: true } ],
errors: [
{
message:
'`SomeComponent` from `@wordpress/ui` is not yet recommended for use in a WordPress environment.',
},
],
},
// Denylist: denied components are flagged with their message.
{
code: "import { __experimentalZStack } from '@wordpress/components';",
Expand Down Expand Up @@ -111,4 +148,12 @@ describe( 'ALLOWLIST and DENYLIST', () => {
);
expect( overlap ).toEqual( [] );
} );

it( 'should not list a component as both allowed and "Use with caution"', () => {
Object.values( ALLOWLIST ).forEach( ( { allowed, caution = [] } ) => {
expect(
caution.filter( ( name ) => allowed.includes( name ) )
).toEqual( [] );
} );
} );
} );
45 changes: 42 additions & 3 deletions packages/eslint-plugin/rules/use-recommended-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ const {
* Allowlist: only the listed components are permitted from these packages.
* Any other named import will be flagged with the package's message.
*
* Components in `caution` are marked "Use with caution". They are flagged
* unless the `allowUseWithCaution` option is enabled.
*
* `message` supports `{{ name }}` and `{{ source }}` placeholders.
*
* @type {Record<string, { allowed: string[], message?: string }>}
* @type {Record<string, { allowed: string[], caution?: string[], message?: string }>}
*/
const ALLOWLIST = {
'@wordpress/ui': {
Expand Down Expand Up @@ -52,6 +55,27 @@ const ALLOWLIST = {
'VisuallyHidden',
'useKeyboardShortcutProps',
],
caution: [
'AlertDialog',
'Breadcrumb',
'Button',
'Checkbox',
'CheckboxGroup',
'Combobox',
'Dialog',
'Drawer',
'IconButton',
'LinkButton',
'Menu',
'Notice',
'Popover',
'Radio',
'RadioGroup',
'SearchableSelect',
'SearchableSelectControl',
'Switch',
'SwitchControl',
],
message:
'`{{ name }}` from `{{ source }}` is not yet recommended for use in a WordPress environment.',
},
Expand Down Expand Up @@ -125,9 +149,20 @@ const rule = {
'Encourage the use of recommended UI components in a WordPress environment.',
url: 'https://github.com/WordPress/gutenberg/blob/HEAD/packages/eslint-plugin/docs/rules/use-recommended-components.md',
},
schema: [],
schema: [
{
type: 'object',
properties: {
allowUseWithCaution: {
type: 'boolean',
},
},
additionalProperties: false,
},
],
},
create( context ) {
const { allowUseWithCaution = false } = context.options[ 0 ] ?? {};
const privateApisState = createPrivateApisState();

return {
Expand Down Expand Up @@ -161,7 +196,11 @@ const rule = {

if (
allowlistEntry &&
! allowlistEntry.allowed.includes( name )
! allowlistEntry.allowed.includes( name ) &&
! (
allowUseWithCaution &&
allowlistEntry.caution?.includes( name )
)
) {
context.report( {
node: specifier,
Expand Down
4 changes: 4 additions & 0 deletions packages/ui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
- `Popover`: Close non-modal popovers when the user presses inside a same-origin iframe. ([#83509](https://github.com/WordPress/gutenberg/pull/83509))
- `CollapsibleCard`: Only show the header's focus ring when its own trigger is keyboard-focused ([#81314](https://github.com/WordPress/gutenberg/pull/81314)).

### Internal

- Document component status in `CONTRIBUTING.md` ([#83536](https://github.com/WordPress/gutenberg/pull/83536)).

## 0.23.0 (2026-09-23)

### Breaking Changes
Expand Down
4 changes: 4 additions & 0 deletions packages/ui/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ When designing props for a new component:

- Provide a `@default` JSDoc tag for the uncontrolled prop when there is a sensible default.

### Component status

When you change a component's Storybook `parameters.componentStatus.status` or its public export, check the `@wordpress/ui` entry in the [`use-recommended-components`](../eslint-plugin/docs/rules/use-recommended-components.md) ESLint rule. `recommended` components belong in `allowed`, `use-with-caution` components in `caution`, and other statuses in neither.

## Compound Components

This package follows the [compound component approach outlined in the `@wordpress/components` contributing guidelines](https://github.com/WordPress/gutenberg/blob/trunk/packages/components/CONTRIBUTING.md#compound-components).
Expand Down
Loading