From 3c93dec4fa61095e7e202006418a2f4b029b0e40 Mon Sep 17 00:00:00 2001 From: Nik Tsekouras Date: Mon, 6 Jul 2020 19:41:50 +0300 Subject: [PATCH 1/6] Enable add row/column buttons after having added one (#23508) * Enable add row/column buttons after having added one. This just allows to be able to add more rows, by enabling the corresponding buttons. It needs to be revised when programmatically focus to RichText is handled. * set selected cell in state * Change comment description Co-authored-by: Miguel Fonseca * Change comment description Co-authored-by: Miguel Fonseca Co-authored-by: Miguel Fonseca --- packages/block-library/src/table/edit.js | 25 ++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/packages/block-library/src/table/edit.js b/packages/block-library/src/table/edit.js index 49f3149b6cde08..4bc6ca81bbdb38 100644 --- a/packages/block-library/src/table/edit.js +++ b/packages/block-library/src/table/edit.js @@ -291,14 +291,23 @@ export class TableEdit extends Component { const { attributes, setAttributes } = this.props; const { sectionName, rowIndex } = selectedCell; + const newRowIndex = rowIndex + delta; - this.setState( { selectedCell: null } ); setAttributes( insertRow( attributes, { sectionName, - rowIndex: rowIndex + delta, + rowIndex: newRowIndex, } ) ); + // Select the first cell of the new row + this.setState( { + selectedCell: { + sectionName, + rowIndex: newRowIndex, + columnIndex: 0, + type: 'cell', + }, + } ); } /** @@ -346,13 +355,21 @@ export class TableEdit extends Component { const { attributes, setAttributes } = this.props; const { columnIndex } = selectedCell; + const newColumnIndex = columnIndex + delta; - this.setState( { selectedCell: null } ); setAttributes( insertColumn( attributes, { - columnIndex: columnIndex + delta, + columnIndex: newColumnIndex, } ) ); + // Select the first cell of the new column + this.setState( { + selectedCell: { + rowIndex: 0, + columnIndex: newColumnIndex, + type: 'cell', + }, + } ); } /** From 5fe0cfb1ba81cf392b333c4a12baf4f666559512 Mon Sep 17 00:00:00 2001 From: Glen Davies Date: Tue, 7 Jul 2020 14:37:32 +1200 Subject: [PATCH 2/6] Add fix to make inputs of type email return true from isTextField (#21162) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add fix to make inputs of type email return true from isTextField to allow native paste to handle pasting in email inputs Co-authored-by: Glen Davies Co-authored-by: Ella van Durpe --- packages/dom/src/dom.js | 37 ++++++++++++++++++------------------ packages/dom/src/test/dom.js | 13 +++++++++++-- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/packages/dom/src/dom.js b/packages/dom/src/dom.js index e16cd41e709661..0a9b51d8b4f0ef 100644 --- a/packages/dom/src/dom.js +++ b/packages/dom/src/dom.js @@ -448,25 +448,24 @@ export function placeCaretAtVerticalEdge( * @return {boolean} True if the element is an text field, false if not. */ export function isTextField( element ) { - try { - const { nodeName, selectionStart, contentEditable } = element; - - return ( - ( nodeName === 'INPUT' && selectionStart !== null ) || - nodeName === 'TEXTAREA' || - contentEditable === 'true' - ); - } catch ( error ) { - // Safari throws an exception when trying to get `selectionStart` - // on non-text elements (which, understandably, don't - // have the text selection API). We catch this via a try/catch - // block, as opposed to a more explicit check of the element's - // input types, because of Safari's non-standard behavior. This - // also means we don't have to worry about the list of input - // types that support `selectionStart` changing as the HTML spec - // evolves over time. - return false; - } + const { nodeName, contentEditable } = element; + const nonTextInputs = [ + 'button', + 'checkbox', + 'hidden', + 'file', + 'radio', + 'image', + 'range', + 'reset', + 'submit', + 'number', + ]; + return ( + ( nodeName === 'INPUT' && ! nonTextInputs.includes( element.type ) ) || + nodeName === 'TEXTAREA' || + contentEditable === 'true' + ); } /** diff --git a/packages/dom/src/test/dom.js b/packages/dom/src/test/dom.js index eabb2ed968bd1a..42dc2ae36912e9 100644 --- a/packages/dom/src/test/dom.js +++ b/packages/dom/src/test/dom.js @@ -107,9 +107,12 @@ describe( 'DOM', () => { const NON_TEXT_INPUT_TYPES = [ 'button', 'checkbox', - 'image', 'hidden', + 'file', 'radio', + 'image', + 'range', + 'reset', 'submit', ]; @@ -118,7 +121,13 @@ describe( 'DOM', () => { * * @type {string[]} */ - const TEXT_INPUT_TYPES = [ 'text', 'password', 'search', 'url' ]; + const TEXT_INPUT_TYPES = [ + 'text', + 'password', + 'search', + 'url', + 'email', + ]; it( 'should return false for non-text input elements', () => { NON_TEXT_INPUT_TYPES.forEach( ( type ) => { From 9d8bd630e9a26188c67e73831e2f0bc2f5908b2e Mon Sep 17 00:00:00 2001 From: Joen A <1204802+jasmussen@users.noreply.github.com> Date: Tue, 7 Jul 2020 07:26:04 +0200 Subject: [PATCH 3/6] Fix radio control in Windows High Contrast mode. (#23706) --- packages/base-styles/_mixins.scss | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/base-styles/_mixins.scss b/packages/base-styles/_mixins.scss index 8cf1b97045367b..ecbdfb029ffa9b 100644 --- a/packages/base-styles/_mixins.scss +++ b/packages/base-styles/_mixins.scss @@ -361,6 +361,9 @@ margin: 8px 0 0 8px; background-color: $white; + // This border serves as a background color in Windows High Contrast mode. + border: 3px solid $white; + @include break-medium() { width: 6px; height: 6px; From 84f7682308b22d622d40c7e1c5d8c1346ef3fea5 Mon Sep 17 00:00:00 2001 From: Joen A <1204802+jasmussen@users.noreply.github.com> Date: Tue, 7 Jul 2020 11:04:03 +0200 Subject: [PATCH 4/6] Add more space for german. (#23738) Co-authored-by: Joen A <> --- .../edit-post/src/components/sidebar/post-schedule/style.scss | 2 +- .../edit-post/src/components/sidebar/post-visibility/style.scss | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/edit-post/src/components/sidebar/post-schedule/style.scss b/packages/edit-post/src/components/sidebar/post-schedule/style.scss index 1ef9b26554eba6..c19896af20ab63 100644 --- a/packages/edit-post/src/components/sidebar/post-schedule/style.scss +++ b/packages/edit-post/src/components/sidebar/post-schedule/style.scss @@ -5,7 +5,7 @@ span { display: block; - width: 35%; + width: 45%; } } diff --git a/packages/edit-post/src/components/sidebar/post-visibility/style.scss b/packages/edit-post/src/components/sidebar/post-visibility/style.scss index 1597025d088b07..7b6be785146639 100644 --- a/packages/edit-post/src/components/sidebar/post-visibility/style.scss +++ b/packages/edit-post/src/components/sidebar/post-visibility/style.scss @@ -4,7 +4,7 @@ span { display: block; - width: 35%; + width: 45%; } } From ce8cb5da59f02f58ce8544b6cfde5e8eb86aa96e Mon Sep 17 00:00:00 2001 From: Q Date: Tue, 7 Jul 2020 13:41:18 -0400 Subject: [PATCH 5/6] UnitControl: Fix internal unit state/parsing to handle incoming unit prop (#23521) This update fixes the `` component to handle (new) incoming `unit` prop changes. This is important for handling interactions such as unit swapping - an interaction we have for the Cover block. --- packages/components/src/unit-control/index.js | 7 +++++-- .../components/src/unit-control/test/index.js | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/packages/components/src/unit-control/index.js b/packages/components/src/unit-control/index.js index 39137c6c132a7a..06f3f9a84d5c6d 100644 --- a/packages/components/src/unit-control/index.js +++ b/packages/components/src/unit-control/index.js @@ -7,7 +7,7 @@ import classnames from 'classnames'; /** * WordPress dependencies */ -import { useState, forwardRef } from '@wordpress/element'; +import { forwardRef } from '@wordpress/element'; /** * Internal dependencies @@ -19,6 +19,7 @@ import { import { Root, ValueInput } from './styles/unit-control-styles'; import UnitSelectControl from './unit-select-control'; import { CSS_UNITS, getParsedValue, getValidParsedUnit } from './utils'; +import { useControlledState } from '../utils/hooks'; function UnitControl( { @@ -43,7 +44,9 @@ function UnitControl( ref ) { const [ value, initialUnit ] = getParsedValue( valueProp, unitProp, units ); - const [ unit, setUnit ] = useState( initialUnit ); + const [ unit, setUnit ] = useControlledState( unitProp, { + initial: initialUnit, + } ); const classes = classnames( 'components-unit-control', className ); diff --git a/packages/components/src/unit-control/test/index.js b/packages/components/src/unit-control/test/index.js index c6b0431c968474..f78abf47781c62 100644 --- a/packages/components/src/unit-control/test/index.js +++ b/packages/components/src/unit-control/test/index.js @@ -3,6 +3,7 @@ */ import { render, unmountComponentAtNode } from 'react-dom'; import { act, Simulate } from 'react-dom/test-utils'; +import { render as testRender } from '@testing-library/react'; /** * WordPress dependencies @@ -372,5 +373,19 @@ describe( 'UnitControl', () => { expect( state ).toBe( '123rem' ); } ); + + it( 'should update unit after initial render and with new unit prop', () => { + const { container: testContainer, rerender } = testRender( + + ); + + const select = testContainer.querySelector( 'select' ); + + expect( select.value ).toBe( '%' ); + + rerender( ); + + expect( select.value ).toBe( 'em' ); + } ); } ); } ); From 6eb9e2b25e200c80048646c687948b46e01ee07e Mon Sep 17 00:00:00 2001 From: Nicolas Brown Date: Mon, 13 Jul 2020 10:45:42 -0500 Subject: [PATCH 6/6] Update button when borderRadius resets (#23887) --- packages/block-library/src/button/edit.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/button/edit.js b/packages/block-library/src/button/edit.js index 02f5497560a9d6..48fbbeb820d184 100644 --- a/packages/block-library/src/button/edit.js +++ b/packages/block-library/src/button/edit.js @@ -41,9 +41,14 @@ const MAX_BORDER_RADIUS_VALUE = 50; const INITIAL_BORDER_RADIUS_POSITION = 5; function BorderPanel( { borderRadius = '', setAttributes } ) { + const initialBorderRadius = borderRadius; const setBorderRadius = useCallback( ( newBorderRadius ) => { - setAttributes( { borderRadius: newBorderRadius } ); + if ( newBorderRadius === undefined ) + setAttributes( { + borderRadius: initialBorderRadius, + } ); + else setAttributes( { borderRadius: newBorderRadius } ); }, [ setAttributes ] );