Skip to content

Commit

Permalink
Backport fixes to include in Gutenberg 8.5.0 (#23783)
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad authored Jul 8, 2020
1 parent 8384ca7 commit 0f07a26
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 18 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

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

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export default function useScrollWhenDragging() {
}, [] );

const scrollOnDragOver = useCallback( ( event ) => {
if ( ! scrollParentY.current ) {
return;
}
const scrollParentHeight = scrollParentY.current.offsetHeight;
const offsetDragStartPosition =
dragStartY.current - scrollParentY.current.offsetTop;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// Overrides the default padding applied in editor styles otherwise preview centering break.
&.editor-styles-wrapper {
padding: 0;
margin: 0;
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/block-editor/src/components/tool-selector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import { __ } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';
import { forwardRef } from '@wordpress/element';
import { edit as editIcon } from '@wordpress/icons';
import { Icon, edit as editIcon } from '@wordpress/icons';

const selectIcon = (
<SVG
Expand Down Expand Up @@ -60,7 +60,7 @@ function ToolSelector( props, ref ) {
value: 'edit',
label: (
<>
{ editIcon }
<Icon icon={ editIcon } />
{ __( 'Edit' ) }
</>
),
Expand Down
18 changes: 12 additions & 6 deletions packages/components/src/tab-panel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { partial, noop, find } from 'lodash';
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';
import { useState, useEffect } from '@wordpress/element';
import { useInstanceId } from '@wordpress/compose';

/**
Expand Down Expand Up @@ -39,9 +39,7 @@ export default function TabPanel( {
onSelect = noop,
} ) {
const instanceId = useInstanceId( TabPanel, 'tab-panel' );
const [ selected, setSelected ] = useState(
initialTabName || ( tabs.length > 0 ? tabs[ 0 ].name : null )
);
const [ selected, setSelected ] = useState( null );

const handleClick = ( tabKey ) => {
setSelected( tabKey );
Expand All @@ -51,9 +49,17 @@ export default function TabPanel( {
const onNavigate = ( childIndex, child ) => {
child.click();
};

const selectedTab = find( tabs, { name: selected } );
const selectedId = `${ instanceId }-${ selectedTab.name }`;
const selectedId = `${ instanceId }-${ selectedTab?.name ?? 'none' }`;

useEffect( () => {
const newSelectedTab = find( tabs, { name: selected } );
if ( ! newSelectedTab ) {
setSelected(
initialTabName || ( tabs.length > 0 ? tabs[ 0 ].name : null )
);
}
}, [ tabs ] );

return (
<div className={ className }>
Expand Down
19 changes: 13 additions & 6 deletions packages/components/src/tab-panel/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ describe( 'TabPanel', () => {
},
};

const wrapper = TestUtils.renderIntoDocument(
getTestComponent( TabPanel, props )
);
let wrapper;
TestUtils.act( () => {
wrapper = TestUtils.renderIntoDocument(
getTestComponent( TabPanel, props )
);
} );

const alphaTab = getElementByClass( wrapper, 'alpha' );
const betaTab = getElementByClass( wrapper, 'beta' );
Expand Down Expand Up @@ -162,9 +165,13 @@ describe( 'TabPanel', () => {
);
},
};
const wrapper = TestUtils.renderIntoDocument(
getTestComponent( TabPanel, props )
);

let wrapper;
TestUtils.act( () => {
wrapper = TestUtils.renderIntoDocument(
getTestComponent( TabPanel, props )
);
} );

const getActiveTab = () => getElementByClass( wrapper, 'active-tab' );
expect( getActiveTab().innerHTML ).toBe( 'Beta' );
Expand Down
3 changes: 2 additions & 1 deletion packages/edit-post/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ body.block-editor-page {
.edit-post-sidebar,
.editor-post-publish-panel,
.components-popover,
.components-modal__frame {
.components-modal__frame,
.edit-post-layout__inserter-panel {
@include reset;
}

Expand Down

0 comments on commit 0f07a26

Please sign in to comment.