Skip to content

Commit

Permalink
Panel: Improve scroll view handling when expanding (#23327)
Browse files Browse the repository at this point in the history
* Add scrollIntoView interaction for PanelBody

Refactor interactions with Reakit/Disclosure.
Add custom hooks for ref and rendering handling.

* Adjust PanelBody story to include scrollIntoView example

* Adjust bottom padding for Layout sidebar

* Allow for opened prop to control disclosure state

* Update PanelBody tests

* Update snapshots

* Fix tests for PanelColorSettings + Update snapshots

* Add new PanelBody props to README

* Add react-merge-refs dependency

* Use react-merge-refs util

* Update test snapshots

* Remove disableSmoothScrollIntoView prop from PanelBody

* Update snapshots

* Remove focusable prop

* Remove use-combined-refs - No longer needed

* Remove onToggle from useUpdateEffect deps array

* Adjust onToggle callback handling

* Remove Reakit/Disclosure integration (for now)

* Update PanelBody tests

* Update snapshots

* Fix initialOpen handling for PanelBody

* Remove unnecessary act wrappers in panel body tests
  • Loading branch information
Q authored Jul 14, 2020
1 parent eb856ef commit bb00ad8
Show file tree
Hide file tree
Showing 12 changed files with 347 additions and 258 deletions.
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

200 changes: 93 additions & 107 deletions packages/block-editor/src/components/panel-color-settings/test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { create, act } from 'react-test-renderer';
import { render } from '@testing-library/react';
import { noop } from 'lodash';

/**
Expand All @@ -11,120 +11,106 @@ import PanelColorSettings from '../';

describe( 'PanelColorSettings', () => {
it( 'should not render anything if there are no colors to choose', async () => {
let root;

await act( async () => {
root = create(
<PanelColorSettings
title="Test Title"
colors={ [] }
disableCustomColors={ true }
colorSettings={ [
{
value: '#000',
onChange: noop,
label: 'border color',
},
{
value: '#111',
onChange: noop,
label: 'background color',
},
] }
/>
);
} );

expect( root.toJSON() ).toBe( null );
const { container } = render(
<PanelColorSettings
title="Test Title"
colors={ [] }
disableCustomColors={ true }
colorSettings={ [
{
value: '#000',
onChange: noop,
label: 'border color',
},
{
value: '#111',
onChange: noop,
label: 'background color',
},
] }
/>
);
expect( container.innerHTML ).toBe( '' );
} );

it( 'should render a color panel if at least one setting supports custom colors', async () => {
let root;
await act( async () => {
root = create(
<PanelColorSettings
title="Test Title"
colors={ [] }
disableCustomColors={ true }
colorSettings={ [
{
value: '#000',
onChange: noop,
label: 'border color',
},
{
value: '#111',
onChange: noop,
label: 'background color',
disableCustomColors: false,
},
] }
/>
);
} );
expect( root ).not.toBe( null );
const { container } = render(
<PanelColorSettings
title="Test Title"
colors={ [] }
disableCustomColors={ true }
colorSettings={ [
{
value: '#000',
onChange: noop,
label: 'border color',
},
{
value: '#111',
onChange: noop,
label: 'background color',
disableCustomColors: false,
},
] }
/>
);
expect( container.innerHTML ).not.toBe( '' );
} );

it( 'should render a color panel if at least one setting specifies some colors to choose', async () => {
let root;
await act( async () => {
root = create(
<PanelColorSettings
title="Test Title"
colors={ [] }
disableCustomColors={ true }
colorSettings={ [
{
value: '#000',
onChange: noop,
label: 'border color',
colors: [
{
slug: 'red',
name: 'Red',
color: '#ff0000',
},
],
},
{
value: '#111',
onChange: noop,
label: 'background color',
},
] }
/>
);
} );
expect( root ).not.toBe( null );
const { container } = render(
<PanelColorSettings
title="Test Title"
colors={ [] }
disableCustomColors={ true }
colorSettings={ [
{
value: '#000',
onChange: noop,
label: 'border color',
colors: [
{
slug: 'red',
name: 'Red',
color: '#ff0000',
},
],
},
{
value: '#111',
onChange: noop,
label: 'background color',
},
] }
/>
);
expect( container.innerHTML ).not.toBe( '' );
} );

it( 'should not render anything if none of the setting panels has colors to choose', async () => {
let root;
await act( async () => {
root = create(
<PanelColorSettings
title="Test Title"
colors={ [] }
disableCustomColors={ false }
colorSettings={ [
{
value: '#000',
onChange: noop,
label: 'border color',
colors: [],
disableCustomColors: true,
},
{
value: '#111',
onChange: noop,
label: 'background color',
colors: [],
disableCustomColors: true,
},
] }
/>
);
} );
expect( root ).not.toBe( null );
const { container } = render(
<PanelColorSettings
title="Test Title"
colors={ [] }
disableCustomColors={ false }
colorSettings={ [
{
value: '#000',
onChange: noop,
label: 'border color',
colors: [],
disableCustomColors: true,
},
{
value: '#111',
onChange: noop,
label: 'background color',
colors: [],
disableCustomColors: true,
},
] }
/>
);
expect( container.innerHTML ).not.toBe( '' );
} );
} );
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
exports[`core/more/edit should match snapshot when noTeaser is false 1`] = `
<React.Fragment>
<InspectorControls>
<ForwardRef(PanelBody)>
<PanelBody>
<ToggleControl
checked={false}
help={[Function]}
label="Hide the excerpt on the full content page"
onChange={[Function]}
/>
</ForwardRef(PanelBody)>
</PanelBody>
</InspectorControls>
<div
className="wp-block-more"
Expand All @@ -33,14 +33,14 @@ exports[`core/more/edit should match snapshot when noTeaser is false 1`] = `
exports[`core/more/edit should match snapshot when noTeaser is true 1`] = `
<React.Fragment>
<InspectorControls>
<ForwardRef(PanelBody)>
<PanelBody>
<ToggleControl
checked={true}
help={[Function]}
label="Hide the excerpt on the full content page"
onChange={[Function]}
/>
</ForwardRef(PanelBody)>
</PanelBody>
</InspectorControls>
<div
className="wp-block-more"
Expand Down
1 change: 1 addition & 0 deletions packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"moment": "^2.22.1",
"re-resizable": "^6.4.0",
"react-dates": "^17.1.1",
"react-merge-refs": "^1.0.0",
"react-resize-aware": "^3.0.1",
"react-spring": "^8.0.20",
"react-use-gesture": "^7.0.15",
Expand Down
Loading

0 comments on commit bb00ad8

Please sign in to comment.