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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const meta: Meta< typeof BaseControl > = {
componentStatus: {
status: 'recommended',
whereUsed: 'global',
notes: 'Will be superseded by [`Field`](?path=/docs/design-system-components-form-primitives-field--docs) in `@wordpress/ui`, but continue using for now.',
notes: '`BaseControl.VisualLabel` can continue to be used for now. To add labels and descriptions semantically, use [`Field`](?path=/docs/design-system-components-form-primitives-field--docs) in `@wordpress/ui`.',
},
},
};
Expand Down
1 change: 1 addition & 0 deletions packages/eslint-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Enhancements

- Update `use-recommended-components` rule to mark `Autocomplete`, `Field`, and `Fieldset` from `@wordpress/ui` as recommended ([#80636](https://github.com/WordPress/gutenberg/pull/80636)).
- Allow the public `@wordpress/ui` keyboard shortcut utilities in the `use-recommended-components` rule. ([#81826](https://github.com/WordPress/gutenberg/pull/81826))
- Update `use-recommended-components` rule to mark `Input`, `InputControl`, and `InputLayout` from `@wordpress/ui` as recommended, and to prefer `@wordpress/ui` `InputControl` over legacy `@wordpress/components` `InputControl` and `TextControl` ([#81658](https://github.com/WordPress/gutenberg/pull/81658)).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ruleTester.run( 'use-recommended-components', rule, {
"import { Link } from '@wordpress/ui';",
"import { Stack } from '@wordpress/ui';",
"import { Text } from '@wordpress/ui';",
"import { Badge, Icon, Link, Stack, Tabs, Text, Tooltip } from '@wordpress/ui';",
"import { Autocomplete, Badge, Field, Fieldset, Icon, Link, Stack, Tabs, Text, Tooltip } from '@wordpress/ui';",
"import { Spinner } from '@wordpress/ui';",
"import { KeyboardShortcutDescription, KeyboardShortcutDisplay, useKeyboardShortcutProps } from '@wordpress/ui';",

Expand Down
3 changes: 3 additions & 0 deletions packages/eslint-plugin/rules/use-recommended-components.js
Comment thread
mirka marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@ const {
const ALLOWLIST = {
'@wordpress/ui': {
allowed: [
'Autocomplete',
'Badge',
'Calendar',
'Card',
'Collapsible',
'CollapsibleCard',
'EmptyState',
'Field',
'Fieldset',
'Icon',
'Input',
'InputControl',
Expand Down
1 change: 1 addition & 0 deletions packages/ui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

### Bug Fixes

- `Autocomplete.Input`, `Combobox.Input`: Omit the `type` prop, since the combobox role is only valid on `input type="text"` ([#80636](https://github.com/WordPress/gutenberg/pull/80636)).
- `Card`: Use the normal neutral surface stroke for the default border. ([#81746](https://github.com/WordPress/gutenberg/pull/81746))

### Documentation
Expand Down
4 changes: 4 additions & 0 deletions packages/ui/src/form/primitives/autocomplete/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { DirectionProvider } from '../../../utils/direction-provider';
* Low-level primitive for an autocomplete input that suggests options as
* you type. Unlike `Combobox`, the input can contain free-form text and
* suggestions only optionally autocomplete the text.
*
* There are currently no plans for higher-level components of this primitive in this package.
* Use the primitives directly, and remember to label the input field,
* usually by using the `Field` component.
*/
export function Root( props: AutocompleteRootProps ) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as Autocomplete from '../index';
import { Icon } from '../../../../icon';
import { Input } from '../../input';
import { InputLayout } from '../../input-layout';
import { Textarea } from '../../textarea';
import {
COMMANDS,
EMOJI_GROUPS,
Expand All @@ -18,6 +17,7 @@ import {
} from './fixtures';

const meta: Meta< typeof Autocomplete.Root > = {
tags: [ 'manifest' ],
title: 'Design System/Components/Form/Primitives/Autocomplete',
component: Autocomplete.Root,
subcomponents: {
Expand All @@ -39,9 +39,8 @@ const meta: Meta< typeof Autocomplete.Root > = {
},
parameters: {
componentStatus: {
status: 'use-with-caution',
status: 'recommended',
whereUsed: 'global',
notes: 'Not yet recommended for use alongside components from `@wordpress/components`, pending review of style consistency with `@wordpress/components`, overlays compatibility, and component set completeness. See [WordPress/gutenberg#76135](https://github.com/WordPress/gutenberg/issues/76135).',
},
},
};
Expand All @@ -56,11 +55,7 @@ export const Default: Story = {
args: {
items: URLS,
children: [
<Autocomplete.Input
placeholder="Enter a URL"
type="url"
key="input"
/>,
<Autocomplete.Input placeholder="Enter a URL" key="input" />,
<Autocomplete.Popup key="popup">
<Autocomplete.Empty>No matching items.</Autocomplete.Empty>
<Autocomplete.List>
Expand Down Expand Up @@ -109,7 +104,7 @@ export const OpenOnlyOnMatch: Story = {
} }
filteredItems={ filteredItems }
>
<Autocomplete.Input placeholder="Enter a URL" type="url" />
<Autocomplete.Input placeholder="Enter a URL" />
<Autocomplete.Popup>
<Autocomplete.List>
<Autocomplete.ListBody>
Expand Down Expand Up @@ -157,7 +152,7 @@ export const AsyncItems: Story = {
}, 500 );
} }
>
<Autocomplete.Input placeholder="Enter a URL" type="url" />
<Autocomplete.Input placeholder="Enter a URL" />
<Autocomplete.Popup>
<Autocomplete.Empty>
{ loading ? 'Loading...' : 'No matching items.' }
Expand Down Expand Up @@ -235,7 +230,6 @@ export const WithSearchIconAndClearButton: Story = {
<Autocomplete.InputGroup key="inputGroup">
<Autocomplete.Input
placeholder="Search URLs"
type="url"
render={
<Input
prefix={
Expand Down Expand Up @@ -274,11 +268,11 @@ export const WithSearchIconAndClearButton: Story = {
};

/**
* Experimental: Textarea with inline autocomplete triggered by `@`.
* Experimental: Inline autocomplete triggered by `@`.
*/
export const TextareaInlineAutocomplete: Story = {
export const InlineMentionAutocomplete: Story = {
render: function Template() {
const textareaRef = useRef< HTMLTextAreaElement >( null );
const inputRef = useRef< HTMLInputElement >( null );
const [ value, setValue ] = useState( '' );
const [ open, setOpen ] = useState( false );
const [ filteredItems, setFilteredItems ] = useState< FixtureItem[] >(
Expand Down Expand Up @@ -327,23 +321,20 @@ export const TextareaInlineAutocomplete: Story = {

const caretPos = before.length + inserted.length;
requestAnimationFrame( () => {
textareaRef.current?.setSelectionRange(
caretPos,
caretPos
);
textareaRef.current?.focus();
inputRef.current?.setSelectionRange( caretPos, caretPos );
inputRef.current?.focus();
} );
return;
}

setValue( newValue );

const textarea = textareaRef.current;
if ( ! textarea ) {
const input = inputRef.current;
if ( ! input ) {
return;
}

const caretPos = textarea.selectionStart ?? 0;
const caretPos = input.selectionStart ?? 0;
const detected = findTrigger( newValue, caretPos );

if ( detected ) {
Expand Down Expand Up @@ -379,12 +370,8 @@ export const TextareaInlineAutocomplete: Story = {
autoHighlight
>
<Autocomplete.Input
render={
<Textarea
ref={ textareaRef }
placeholder="Type @ to mention someone"
/>
}
ref={ inputRef }
placeholder="Type @ to mention someone"
/>

<Autocomplete.Popup>
Expand Down Expand Up @@ -429,11 +416,7 @@ export const WithCustomZIndex: Story = {
args: {
items: URLS,
children: [
<Autocomplete.Input
placeholder="Enter a URL"
type="url"
key="input"
/>,
<Autocomplete.Input placeholder="Enter a URL" key="input" />,
<Autocomplete.Popup
portal={
<Autocomplete.Portal
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/form/primitives/autocomplete/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export type AutocompleteGroupLabelProps = ComponentProps<

export type AutocompleteInputProps = Omit<
ComponentProps< typeof _Autocomplete.Input >,
'size'
'size' | 'type' // The combobox role is only valid on input type="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.

Consumers would still be able to use render, eg doing render={ <Input type="url" /> } or render={ <textarea /> }.

Depending on how much we wan to enforce this, we may want to make the render type stricter, and / or force the type to text at runtime

>;

export type AutocompleteInputGroupProps = ComponentProps<
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/form/primitives/combobox/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export type ComboboxGroupLabelProps = ComponentProps<

export type ComboboxInputProps = Omit<
ComponentProps< typeof _Combobox.Input >,
'size'
'size' | 'type' // The combobox role is only valid on input type="text".
>;

export type ComboboxInputGroupProps = ComponentProps<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as Field from '../';
import { DETAILS_EXAMPLE } from '../../../stories/shared';

const meta: Meta< typeof Field.Root > = {
tags: [ 'manifest' ],
title: 'Design System/Components/Form/Primitives/Field',
component: Field.Root,
subcomponents: {
Expand All @@ -15,9 +16,8 @@ const meta: Meta< typeof Field.Root > = {
},
parameters: {
componentStatus: {
status: 'use-with-caution',
status: 'recommended',
whereUsed: 'global',
notes: 'Not yet recommended for use alongside components from `@wordpress/components`, pending review of style consistency with `@wordpress/components` and component set completeness. See [WordPress/gutenberg#76135](https://github.com/WordPress/gutenberg/issues/76135).',
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,23 @@ import * as Fieldset from '../';
import { DETAILS_EXAMPLE } from '../../../stories/shared';

const meta: Meta< typeof Fieldset.Root > = {
tags: [ 'manifest' ],
title: 'Design System/Components/Form/Primitives/Fieldset',
component: Fieldset.Root,
// Temporary: Due to an upstream bug, render the root explicitly so the
// components manifest extractor can resolve props from the JSX.
//
// See: https://github.com/storybookjs/storybook/issues/34877
render: ( args ) => <Fieldset.Root { ...args } />,
subcomponents: {
'Fieldset.Legend': Fieldset.Legend,
'Fieldset.Description': Fieldset.Description,
'Fieldset.Details': Fieldset.Details,
},
parameters: {
componentStatus: {
status: 'use-with-caution',
status: 'recommended',
whereUsed: 'global',
notes: 'Not yet recommended for use alongside components from `@wordpress/components`, pending review of style consistency with `@wordpress/components` and component set completeness. See [WordPress/gutenberg#76135](https://github.com/WordPress/gutenberg/issues/76135).',
},
},
};
Expand Down
6 changes: 6 additions & 0 deletions packages/ui/src/form/primitives/stories/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ These form primitives are the low-level building blocks for form-related compone
3. If not, then these primitives are the next best option. Keep in mind that you are responsible for ensuring that your implementation is accessible, and adheres to Design System guidelines.

Feel free to reach out to the `#design-system` channel on the [Make WordPress Slack](https://make.wordpress.org/chat/) for guidance.

## Labels and descriptions

Form primitives do not provide labels or descriptions on their own. When you compose them directly, you are responsible for associating each control with an accessible name and, when needed, an accessible description.

For standard labels and descriptions, use [Field](?path=/docs/design-system-components-form-primitives-field--docs) for individual controls and [Fieldset](?path=/docs/design-system-components-form-primitives-fieldset--docs) for groups of related controls.
Loading
Loading