Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/block-editor/src/components/url-input/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ _Required._ Called when the value changes. The second parameter is `null` unless
}
```

### `onKeydown`: `( event: KeyboardEvent ) => void`

A callback invoked on the keydown event.

- Required: No
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we inherit all normal input props?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this could be a follow up. We can land this for now, no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! :)


### `label: String`

_Optional._ If this property is added, a label will be generated using label property as the content.
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/components/url-input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ class URLInput extends Component {
}

onKeyDown( event ) {
this.props.onKeyDown?.( event );
const { showSuggestions, selectedSuggestion, suggestions, loading } =
this.state;

Expand Down
77 changes: 51 additions & 26 deletions packages/block-library/src/social-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import classNames from 'classnames';
/**
* WordPress dependencies
*/
import { DELETE, BACKSPACE } from '@wordpress/keycodes';
import { useDispatch } from '@wordpress/data';

import {
InspectorControls,
URLPopover,
URLInput,
useBlockProps,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useState } from '@wordpress/element';
import {
Expand All @@ -32,40 +36,60 @@ const SocialLinkURLPopover = ( {
setAttributes,
setPopover,
popoverAnchor,
} ) => (
<URLPopover anchor={ popoverAnchor } onClose={ () => setPopover( false ) }>
<form
className="block-editor-url-popover__link-editor"
onSubmit={ ( event ) => {
event.preventDefault();
setPopover( false );
} }
clientId,
} ) => {
const { removeBlock } = useDispatch( blockEditorStore );
return (
<URLPopover
anchor={ popoverAnchor }
onClose={ () => setPopover( false ) }
>
<div className="block-editor-url-input">
<URLInput
__nextHasNoMarginBottom
value={ url }
onChange={ ( nextURL ) =>
setAttributes( { url: nextURL } )
}
placeholder={ __( 'Enter address' ) }
disableSuggestions={ true }
<form
className="block-editor-url-popover__link-editor"
onSubmit={ ( event ) => {
event.preventDefault();
setPopover( false );
} }
>
<div className="block-editor-url-input">
<URLInput
__nextHasNoMarginBottom
value={ url }
onChange={ ( nextURL ) =>
setAttributes( { url: nextURL } )
}
placeholder={ __( 'Enter address' ) }
disableSuggestions={ true }
onKeyDown={ ( event ) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mostly whitespace changes besides the onKeyDown and the useDispatch line.

if (
!! url ||
event.defaultPrevented ||
! [ BACKSPACE, DELETE ].includes(
event.keyCode
)
) {
return;
}
removeBlock( clientId );
} }
/>
</div>
<Button
icon={ keyboardReturn }
label={ __( 'Apply' ) }
type="submit"
/>
</div>
<Button
icon={ keyboardReturn }
label={ __( 'Apply' ) }
type="submit"
/>
</form>
</URLPopover>
);
</form>
</URLPopover>
);
};

const SocialLinkEdit = ( {
attributes,
context,
isSelected,
setAttributes,
clientId,
} ) => {
const { url, service, label, rel } = attributes;
const { showLabels, iconColorValue, iconBackgroundColorValue } = context;
Expand Down Expand Up @@ -143,6 +167,7 @@ const SocialLinkEdit = ( {
setAttributes={ setAttributes }
setPopover={ setPopover }
popoverAnchor={ popoverAnchor }
clientId={ clientId }
/>
) }
</Button>
Expand Down