Add step prop to NumberControl (#42928)
* Add step prop to NumberControl * Add step to block attributes as well * Add documentation
This commit is contained in:
parent
a72f3ee7a2
commit
f83a2a8ae8
|
@ -0,0 +1,4 @@
|
|||
Significance: minor
|
||||
Type: add
|
||||
|
||||
Add step prop to NumberControl
|
|
@ -71,6 +71,14 @@ The minimum numeric value that can be entered in the field.
|
|||
|
||||
The maximum numeric value that can be entered in the field.
|
||||
|
||||
### step
|
||||
|
||||
- **Type:** `Number`
|
||||
- **Required:** `No`
|
||||
- **Default:** `1`
|
||||
|
||||
The amount that is incremented or decremented when using the up/down arrows.
|
||||
|
||||
## Usage
|
||||
|
||||
Here's a snippet that adds a field similar to the previous screenshot:
|
||||
|
|
|
@ -36,6 +36,10 @@
|
|||
"required": {
|
||||
"type": "boolean",
|
||||
"default": false
|
||||
},
|
||||
"step": {
|
||||
"type": "number",
|
||||
"default": 1
|
||||
}
|
||||
},
|
||||
"supports": {
|
||||
|
|
|
@ -31,6 +31,7 @@ export function Edit( {
|
|||
required,
|
||||
tooltip,
|
||||
disabled,
|
||||
step,
|
||||
} = attributes;
|
||||
const [ value, setValue ] = useProductEntityProp( property, {
|
||||
postType,
|
||||
|
@ -93,6 +94,7 @@ export function Edit( {
|
|||
required={ required }
|
||||
tooltip={ tooltip }
|
||||
disabled={ disabled }
|
||||
step={ step }
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -13,4 +13,5 @@ export interface NumberBlockAttributes extends BlockAttributes {
|
|||
max?: number;
|
||||
required?: boolean;
|
||||
tooltip?: string;
|
||||
step?: number;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ export type NumberProps = {
|
|||
required?: boolean;
|
||||
tooltip?: string;
|
||||
disabled?: boolean;
|
||||
step?: number;
|
||||
};
|
||||
|
||||
export const NumberControl: React.FC< NumberProps > = ( {
|
||||
|
@ -42,6 +43,7 @@ export const NumberControl: React.FC< NumberProps > = ( {
|
|||
tooltip,
|
||||
placeholder,
|
||||
disabled,
|
||||
step,
|
||||
}: NumberProps ) => {
|
||||
const inputProps = useNumberInputProps( {
|
||||
value: value || '',
|
||||
|
@ -67,6 +69,7 @@ export const NumberControl: React.FC< NumberProps > = ( {
|
|||
>
|
||||
<InputControl
|
||||
{ ...inputProps }
|
||||
step={ step }
|
||||
disabled={ disabled }
|
||||
id={ id }
|
||||
suffix={ suffix }
|
||||
|
|
Loading…
Reference in New Issue