Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Editor: LinkControl: Align documentation with current behavior #19736

Merged
merged 4 commits into from
Jan 20, 2020
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
19 changes: 5 additions & 14 deletions packages/block-editor/src/components/link-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@

## Props

### className

- Type: `String`
- Required: Yes

### value

- Type: `Object`
- Required: Yes
- Required: No

### settings

Expand All @@ -28,8 +23,6 @@

An array of settings objects. Each object will used to render a `ToggleControl` for that setting.

## Event handlers

### onClose

- Type: `Function`
Expand All @@ -41,14 +34,12 @@ An array of settings objects. Each object will used to render a `ToggleControl`
- Required: No

Use this callback to take an action after a user set or updated a link.
The function callback will receive the selected item, or Null.
The function callback will receive the selected item.

```es6
```jsx
<LinkControl
onLinkChange={ ( item ) => {
item
? console.log( `The item selected has the ${ item.id } id.` )
: console.warn( 'No Item selected.' );
onChange={ ( item ) => {
console.log( `The item selected has the ${ item.id } id.` );
}
/>
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Basic rendering should display with required props 1`] = `"<div class=\\"block-editor-link-control\\"><form><div class=\\"components-base-control block-editor-url-input block-editor-link-control__search-input\\"><div class=\\"components-base-control__field\\"><input type=\\"text\\" aria-label=\\"URL\\" required=\\"\\" placeholder=\\"Search or type url\\" role=\\"combobox\\" aria-expanded=\\"false\\" aria-autocomplete=\\"list\\" aria-owns=\\"block-editor-url-input-suggestions-0\\" value=\\"\\"></div></div><button type=\\"reset\\" disabled=\\"\\" class=\\"components-button block-editor-link-control__search-reset has-icon\\" aria-label=\\"Reset\\"><svg aria-hidden=\\"true\\" role=\\"img\\" focusable=\\"false\\" xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"20\\" height=\\"20\\" viewBox=\\"0 0 20 20\\" class=\\"dashicon dashicons-no-alt\\"><path d=\\"M14.95 6.46L11.41 10l3.54 3.54-1.41 1.41L10 11.42l-3.53 3.53-1.42-1.42L8.58 10 5.05 6.47l1.42-1.42L10 8.58l3.54-3.53z\\"></path></svg></button></form></div>"`;
exports[`Basic rendering should render 1`] = `"<div class=\\"block-editor-link-control\\"><form><div class=\\"components-base-control block-editor-url-input block-editor-link-control__search-input\\"><div class=\\"components-base-control__field\\"><input type=\\"text\\" aria-label=\\"URL\\" required=\\"\\" placeholder=\\"Search or type url\\" role=\\"combobox\\" aria-expanded=\\"false\\" aria-autocomplete=\\"list\\" aria-owns=\\"block-editor-url-input-suggestions-0\\" value=\\"\\"></div></div><button type=\\"reset\\" disabled=\\"\\" class=\\"components-button block-editor-link-control__search-reset has-icon\\" aria-label=\\"Reset\\"><svg aria-hidden=\\"true\\" role=\\"img\\" focusable=\\"false\\" xmlns=\\"http://www.w3.org/2000/svg\\" width=\\"20\\" height=\\"20\\" viewBox=\\"0 0 20 20\\" class=\\"dashicon dashicons-no-alt\\"><path d=\\"M14.95 6.46L11.41 10l3.54 3.54-1.41 1.41L10 11.42l-3.53 3.53-1.42-1.42L8.58 10 5.05 6.47l1.42-1.42L10 8.58l3.54-3.53z\\"></path></svg></button></form></div>"`;
13 changes: 4 additions & 9 deletions packages/block-editor/src/components/link-control/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,15 @@ afterEach( () => {
} );

describe( 'Basic rendering', () => {
it( 'should display with required props', () => {
it( 'should render', () => {
act( () => {
render(
<LinkControl
/>, container
);
render( <LinkControl />, container );
} );

// Search Input UI
const searchInput = container.querySelector( 'input[aria-label="URL"]' );

// expect( searchInputLabel ).not.toBeNull();
expect( searchInput ).not.toBeNull();

expect( container.innerHTML ).toMatchSnapshot();
} );
} );
Expand Down Expand Up @@ -465,7 +460,7 @@ describe( 'Selecting links', () => {
} ], // url
] )( 'should display a current selected link UI when a %s suggestion for the search "%s" is clicked', async ( type, searchTerm, selectedLink ) => {
const LinkControlConsumer = () => {
const [ link, setLink ] = useState( null );
const [ link, setLink ] = useState();

return (
<LinkControl
Expand Down Expand Up @@ -524,7 +519,7 @@ describe( 'Selecting links', () => {
} ], // url
] )( 'should display a current selected link UI when an %s suggestion for the search "%s" is selected using the keyboard', async ( type, searchTerm, selectedLink ) => {
const LinkControlConsumer = () => {
const [ link, setLink ] = useState( null );
const [ link, setLink ] = useState();

return (
<LinkControl
Expand Down