Skip to content

Commit

Permalink
Properly associate the sapcer height input label.
Browse files Browse the repository at this point in the history
  • Loading branch information
afercia committed May 23, 2018
1 parent 7ad3fa4 commit 7a29eb0
Showing 1 changed file with 58 additions and 55 deletions.
113 changes: 58 additions & 55 deletions core-blocks/spacer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import ResizableBox from 're-resizable';
import { Fragment } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { InspectorControls } from '@wordpress/editor';
import { BaseControl, PanelBody } from '@wordpress/components';
import { BaseControl, PanelBody, withInstanceId } from '@wordpress/components';

/**
* Internal dependencies
Expand All @@ -34,61 +34,64 @@ export const settings = {
},
},

edit( { attributes, setAttributes, toggleSelection } ) {
const { height } = attributes;
edit: withInstanceId(
( { attributes, setAttributes, toggleSelection, instanceId } ) => {
const { height } = attributes;
const id = `block-spacer-height-input-${ instanceId }`;

return (
<Fragment>
<ResizableBox
size={ {
height,
} }
minHeight="20"
handleClasses={ {
top: 'wp-block-spacer__resize-handler-top',
bottom: 'wp-block-spacer__resize-handler-bottom',
} }
enable={ {
top: true,
right: false,
bottom: true,
left: false,
topRight: false,
bottomRight: false,
bottomLeft: false,
topLeft: false,
} }
onResizeStop={ ( event, direction, elt, delta ) => {
setAttributes( {
height: parseInt( height + delta.height, 10 ),
} );
toggleSelection( true );
} }
onResizeStart={ () => {
toggleSelection( false );
} }
/>
<InspectorControls>
<PanelBody title={ __( 'Spacer Settings' ) }>
<BaseControl label={ __( 'Height in pixels' ) }>
<input
type="number"
onChange={ ( event ) => {
setAttributes( {
height: parseInt( event.target.value, 10 ),
} );
} }
aria-label={ __( 'Height for the spacer element in pixels.' ) }
value={ height }
min="20"
step="10"
/>
</BaseControl>
</PanelBody>
</InspectorControls>
</Fragment>
);
},
return (
<Fragment>
<ResizableBox
size={ {
height,
} }
minHeight="20"
handleClasses={ {
top: 'block-spacer__resize-handler-top',
bottom: 'block-spacer__resize-handler-bottom',
} }
enable={ {
top: true,
right: false,
bottom: true,
left: false,
topRight: false,
bottomRight: false,
bottomLeft: false,
topLeft: false,
} }
onResizeStop={ ( event, direction, elt, delta ) => {
setAttributes( {
height: parseInt( height + delta.height, 10 ),
} );
toggleSelection( true );
} }
onResizeStart={ () => {
toggleSelection( false );
} }
/>
<InspectorControls>
<PanelBody title={ __( 'Spacer Settings' ) }>
<BaseControl label={ __( 'Height in pixels' ) } id={ id }>
<input
type="number"
id={ id }
onChange={ ( event ) => {
setAttributes( {
height: parseInt( event.target.value, 10 ),
} );
} }
value={ height }
min="20"
step="10"
/>
</BaseControl>
</PanelBody>
</InspectorControls>
</Fragment>
);
}
),

save( { attributes } ) {
return <div style={ { height: attributes.height } } aria-hidden />;
Expand Down

0 comments on commit 7a29eb0

Please sign in to comment.