From 6a049e5e9075c0fe5f56382f112526b8b2e1711c Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Sun, 28 Oct 2018 10:18:36 +0100 Subject: [PATCH] Try avoiding the deprecated findDOMNode API --- packages/components/src/drop-zone/provider.js | 17 ++++++++--------- packages/components/src/drop-zone/style.scss | 4 ++++ test/e2e/specs/adding-blocks.test.js | 16 +++++++++++++++- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/packages/components/src/drop-zone/provider.js b/packages/components/src/drop-zone/provider.js index 07e46c37e9a3a5..e12face56f16fa 100644 --- a/packages/components/src/drop-zone/provider.js +++ b/packages/components/src/drop-zone/provider.js @@ -6,7 +6,7 @@ import { isEqual, find, some, filter, throttle, includes } from 'lodash'; /** * WordPress dependencies */ -import { Component, createContext, findDOMNode } from '@wordpress/element'; +import { Component, createContext, createRef } from '@wordpress/element'; import isShallowEqual from '@wordpress/is-shallow-equal'; const { Provider, Consumer } = createContext( { @@ -61,6 +61,7 @@ class DropZoneProvider extends Component { this.resetDragState = this.resetDragState.bind( this ); this.toggleDraggingOverDocument = throttle( this.toggleDraggingOverDocument.bind( this ), 200 ); + this.container = createRef(); this.dropZones = []; this.dropZoneCallbacks = { addDropZone: this.addDropZone, @@ -79,10 +80,6 @@ class DropZoneProvider extends Component { window.addEventListener( 'dragover', this.onDragOver ); window.addEventListener( 'drop', this.onDrop ); window.addEventListener( 'mouseup', this.resetDragState ); - - // Disable reason: Can't use a ref since this component just renders its children - // eslint-disable-next-line react/no-find-dom-node - this.container = findDOMNode( this ); } componentWillUnmount() { @@ -212,7 +209,7 @@ class DropZoneProvider extends Component { const { position, hoveredDropZone } = this.state; const dragEventType = getDragEventType( event ); const dropZone = this.dropZones[ hoveredDropZone ]; - const isValidDropzone = !! dropZone && this.container.contains( event.target ); + const isValidDropzone = !! dropZone && this.container.current.contains( event.target ); this.resetDragState(); if ( isValidDropzone ) { @@ -234,9 +231,11 @@ class DropZoneProvider extends Component { render() { return ( - - { this.props.children } - +
+ + { this.props.children } + +
); } } diff --git a/packages/components/src/drop-zone/style.scss b/packages/components/src/drop-zone/style.scss index 65b67953004246..0103f4af011588 100644 --- a/packages/components/src/drop-zone/style.scss +++ b/packages/components/src/drop-zone/style.scss @@ -58,3 +58,7 @@ .components-drop-zone__content-text { font-family: $default-font; } + +.components-drop-zone__provider { + height: 100%; +} diff --git a/test/e2e/specs/adding-blocks.test.js b/test/e2e/specs/adding-blocks.test.js index 4a444ebe2eb224..16b1a07b6eea94 100644 --- a/test/e2e/specs/adding-blocks.test.js +++ b/test/e2e/specs/adding-blocks.test.js @@ -13,9 +13,23 @@ describe( 'adding blocks', () => { await newPost(); } ); + /** + * Given a Puppeteer ElementHandle, clicks below its bounding box. + * + * @param {Puppeteer.ElementHandle} elementHandle Element handle. + * + * @return {Promise} Promise resolving when click occurs. + */ + async function clickBelow( elementHandle ) { + const box = await elementHandle.boundingBox(); + const x = box.x + ( box.width / 2 ); + const y = box.y + box.height + 100; + return page.mouse.click( x, y ); + } + it( 'Should insert content using the placeholder and the regular inserter', async () => { // Click below editor to focus last field (block appender) - await page.click( '.editor-writing-flow__click-redirect' ); + await clickBelow( await page.$( '.editor-default-block-appender' ) ); expect( await page.$( '[data-type="core/paragraph"]' ) ).not.toBeNull(); await page.keyboard.type( 'Paragraph block' );