diff --git a/packages/block-editor/src/components/alignment-control/README.md b/packages/block-editor/src/components/alignment-control/README.md index 24aa31aef9dfa..d521a23c23b2b 100644 --- a/packages/block-editor/src/components/alignment-control/README.md +++ b/packages/block-editor/src/components/alignment-control/README.md @@ -44,6 +44,13 @@ _Note:_ In this example that we render `AlignmentControl` as a child of the `Blo The current value of the alignment setting. You may only choose from the `Options` listed above. +### `placeholder` +- **Type:** `String` +- **Default:** `left` for left-to-right languages, `right` for right-to-left languages +- **Options:**: `left`, `center`, `right` + +The placeholder alignment value that will be reflected by the toolbar icon when the value is `undefined`. If the content inside your block is aligned to center when no specific `value` is defined, you should set `placeholder` to `center`. + ### `onChange` - **Type:** `Function` diff --git a/packages/block-editor/src/components/alignment-control/test/__snapshots__/index.js.snap b/packages/block-editor/src/components/alignment-control/test/__snapshots__/index.js.snap index 4f549af0b2dc1..445f88c555261 100644 --- a/packages/block-editor/src/components/alignment-control/test/__snapshots__/index.js.snap +++ b/packages/block-editor/src/components/alignment-control/test/__snapshots__/index.js.snap @@ -1,5 +1,81 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`AlignmentUI should allow a custom placeholder to be specified 1`] = ` + + + , + "isActive": false, + "onClick": [Function], + "role": "menuitemradio", + "title": "Align text left", + }, + Object { + "align": "center", + "icon": + + , + "isActive": false, + "onClick": [Function], + "role": "menuitemradio", + "title": "Align text center", + }, + Object { + "align": "right", + "icon": + + , + "isActive": false, + "onClick": [Function], + "role": "menuitemradio", + "title": "Align text right", + }, + ] + } + icon={ + + + + } + label="Align" + popoverProps={ + Object { + "isAlternate": true, + "position": "bottom right", + } + } + toggleProps={ + Object { + "describedBy": "Change text alignment", + } + } +/> +`; + exports[`AlignmentUI should allow custom alignment controls to be specified 1`] = ` { expect( onChangeSpy ).toHaveBeenCalledWith( 'center' ); } ); + test( 'should allow a custom placeholder to be specified', () => { + const wrapperPlaceholder = shallow( + + ); + expect( wrapperPlaceholder ).toMatchSnapshot(); + + const wrapperIllegalPlaceholder = () => + shallow( ); + expect( wrapperIllegalPlaceholder ).not.toThrowError(); + } ); + test( 'should allow custom alignment controls to be specified', () => { const wrapperCustomControls = shallow( control.align === value ); + const placeholderAlignment = find( + alignmentControls, + ( control ) => control.align === placeholder + ); + function setIcon() { if ( activeAlignment ) return activeAlignment.icon; + if ( placeholderAlignment ) return placeholderAlignment.icon; + return isRTL() ? alignRight : alignLeft; }