InputControl 是一个实验性的 React 组件,用于让用户输入和编辑文本,旨在未来与 TextControl 合并或替换它。组件目前处于早期阶段,可能发生重大变更。
import { __experimentalInputControl as InputControl } from '@wordpress/components';
import { useState } from 'react';
const Example = () => {
const [ value, setValue ] = useState( '' );
return (
<InputControl
__next40pxDefaultSize
value={ value }
onChange={ ( nextValue ) => setValue( nextValue ?? '' ) }
/>
);
};由于是实验性组件,开发者在使用时需注意其不稳定性和未来可能的变更。
InputControl components let users enter and edit text. This is an experimental component intended to (in time) merge with or replace TextControl.
import { __experimentalInputControl as InputControl } from '@wordpress/components';
import { useState } from 'react';
const Example = () => {
const [ value, setValue ] = useState( '' );
return (
<InputControl
__next40pxDefaultSize
value={ value }
onChange={ ( nextValue ) => setValue( nextValue ?? '' ) }
/>
);
};
If true, the input will be disabled.
BooleanfalseIf true, the ENTER key press is required in order to trigger an onChange. If enabled, a change is also triggered when tabbing away (onBlur).
BooleanfalseIf true, the label will only be visible to screen readers.
BooleanIf this property is added, a label will be generated using label property as the content.
StringThe position of the label (top, side, bottom, or edge).
StringA function that receives the value of the input.
FunctionRenders an element on the left side of the input.
React.ReactNodeAdjusts the size of the input.
Sizes include: default, small
StringdefaultRenders an element on the right side of the input.
React.ReactNodeType of the input element to render. Defaults to “text”.
StringThe current value of the input.
StringStart opting into the larger default height that will become the default size in a future version.
Booleanfalse