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

Try avoiding the deprecated findDOMNode API from DropZone Provider #11168

Merged
merged 2 commits into from
Nov 1, 2018
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: 7 additions & 12 deletions packages/components/src/drop-zone/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } from '@wordpress/element';
import isShallowEqual from '@wordpress/is-shallow-equal';

const { Provider, Consumer } = createContext( {
Expand Down Expand Up @@ -77,17 +77,11 @@ class DropZoneProvider extends Component {

componentDidMount() {
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() {
window.removeEventListener( 'dragover', this.onDragOver );
window.removeEventListener( 'drop', this.onDrop );
window.removeEventListener( 'mouseup', this.resetDragState );
}

Expand Down Expand Up @@ -212,10 +206,9 @@ 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 );
this.resetDragState();

if ( isValidDropzone ) {
if ( dropZone ) {
switch ( dragEventType ) {
case 'file':
dropZone.onFilesDrop( [ ...event.dataTransfer.files ], position );
Expand All @@ -234,9 +227,11 @@ class DropZoneProvider extends Component {

render() {
return (
<Provider value={ this.dropZoneCallbacks }>
{ this.props.children }
</Provider>
<div onDrop={ this.onDrop } className="components-drop-zone__provider">
<Provider value={ this.dropZoneCallbacks }>
{ this.props.children }
</Provider>
</div>
);
}
}
Expand Down
4 changes: 4 additions & 0 deletions packages/components/src/drop-zone/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,7 @@
.components-drop-zone__content-text {
font-family: $default-font;
}

.components-drop-zone__provider {
height: 100%;
}
16 changes: 15 additions & 1 deletion test/e2e/specs/adding-blocks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );

Expand Down