Skip to content

Commit

Permalink
URLInput: Add flag to remove bottom margin
Browse files Browse the repository at this point in the history
  • Loading branch information
brookewp committed Dec 20, 2022
1 parent 696d63f commit d92f2b9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/block-editor/src/components/url-input/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ When hiding the URLInput using CSS (as is sometimes done for accessibility purpo

This prop allows the suggestions list to be programmatically not rendered by passing a boolean—it can be `true` to make sure suggestions aren't rendered, or `false`/`undefined` to fall back to the default behaviour of showing suggestions when matching autocompletion items are found.

### `__nextHasNoMarginBottom`

- **Type:** `boolean`
- **Default:** `false`

Start opting into the new margin-free styles that will become the default in a future version, currently scheduled to be WordPress 6.4. (The prop can be safely removed once this happens.)

## Example

{% codetabs %}
Expand Down Expand Up @@ -217,6 +224,7 @@ registerBlockType( /* ... */, {
edit( { className, attributes, setAttributes } ) {
return (
<URLInput
__nextHasNoMarginBottom
className={ className }
value={ attributes.url }
onChange={ ( url, post ) => setAttributes( { url, text: (post && post.title) || 'Click here' } ) }
Expand Down
16 changes: 15 additions & 1 deletion packages/block-editor/src/components/url-input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import scrollIntoView from 'dom-scroll-into-view';
/**
* WordPress dependencies
*/
import deprecated from '@wordpress/deprecated';
import { __, sprintf, _n } from '@wordpress/i18n';
import { Component, createRef } from '@wordpress/element';
import { UP, DOWN, ENTER, TAB } from '@wordpress/keycodes';
Expand Down Expand Up @@ -424,6 +425,8 @@ class URLInput extends Component {

renderControl() {
const {
/** Start opting into the new margin-free styles that will become the default in a future version. */
__nextHasNoMarginBottom = false,
label = null,
className,
isFullWidth,
Expand Down Expand Up @@ -477,8 +480,19 @@ class URLInput extends Component {
return renderControl( controlProps, inputProps, loading );
}

if ( ! __nextHasNoMarginBottom ) {
deprecated( 'Bottom margin styles for wp.blockEditor.URLInput', {
since: '6.1',
version: '6.4',
hint: 'Set the `__nextHasNoMarginBottom` prop to true to start opting into the new styles, which will become the default in a future version',
} );
}

return (
<BaseControl { ...controlProps }>
<BaseControl
__nextHasNoMarginBottom={ __nextHasNoMarginBottom }
{ ...controlProps }
>
<input { ...inputProps } />
{ loading && <Spinner /> }
</BaseControl>
Expand Down

0 comments on commit d92f2b9

Please sign in to comment.