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

Writing Flow: Stretch "Click Redirect" to occupy full height of content #18732

Merged
merged 3 commits into from
Dec 2, 2019
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
1 change: 1 addition & 0 deletions packages/block-editor/src/components/typewriter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ class Typewriter extends Component {
onKeyUp={ this.maintainCaretPosition }
onMouseDown={ this.addSelectionChangeListener }
onTouchStart={ this.addSelectionChangeListener }
className="block-editor__typewriter"
>
{ this.props.children }
</div>
Expand Down
6 changes: 5 additions & 1 deletion packages/e2e-test-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
## master
## Master

### Breaking Changes

- The disableNavigationMode utility was removed. By default, the editor is in edit mode now.

### Improvements

- `setBrowserViewport` accepts an object of `width`, `height` values, to assign a viewport of arbitrary size.

## 3.0.0 (2019-11-14)

### Breaking Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-test-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ Sets browser viewport to specified type.

_Parameters_

- _type_ `string`: String to represent dimensions type; can be either small or large.
- _viewport_ `WPViewport`: Viewport name or dimensions object to assign.

<a name="setPostContent" href="#setPostContent">#</a> **setPostContent**

Expand Down
52 changes: 42 additions & 10 deletions packages/e2e-test-utils/src/set-browser-viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,50 @@
*/
import { waitForWindowDimensions } from './wait-for-window-dimensions';

/**
* Named viewport options.
*
* @typedef {"large"|"medium"|"small"} WPDimensionsName
*/

/**
* Viewport dimensions object.
*
* @typedef {Object} WPViewportDimensions
*
* @property {number} width Width, in pixels.
* @property {number} height Height, in pixels.
*/

/**
* Predefined viewport dimensions to reference by name.
*
* @enum {WPViewportDimensions}
*
* @type {Object<WPDimensionsName,WPViewportDimensions>}
*/
const PREDEFINED_DIMENSIONS = {
large: { width: 960, height: 700 },
medium: { width: 768, height: 700 },
small: { width: 600, height: 700 },
};

/**
* Valid argument argument type from which to derive viewport dimensions.
*
* @typedef {WPDimensionsName|WPViewportDimensions} WPViewport
*/

/**
* Sets browser viewport to specified type.
*
* @param {string} type String to represent dimensions type; can be either small or large.
* @param {WPViewport} viewport Viewport name or dimensions object to assign.
*/
export async function setBrowserViewport( type ) {
const allowedDimensions = {
large: { width: 960, height: 700 },
medium: { width: 768, height: 700 },
small: { width: 600, height: 700 },
};
const currentDimension = allowedDimensions[ type ];
await page.setViewport( currentDimension );
await waitForWindowDimensions( currentDimension.width, currentDimension.height );
export async function setBrowserViewport( viewport ) {
const dimensions = typeof viewport === 'string' ?
PREDEFINED_DIMENSIONS[ viewport ] :
viewport;

await page.setViewport( dimensions );
await waitForWindowDimensions( dimensions.width, dimensions.height );
}
12 changes: 9 additions & 3 deletions packages/e2e-tests/specs/editor/various/adding-blocks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
getEditedPostContent,
pressKeyTimes,
switchEditorModeTo,
setBrowserViewport,
} from '@wordpress/e2e-test-utils';

describe( 'adding blocks', () => {
Expand All @@ -21,19 +22,24 @@ describe( 'adding blocks', () => {
*
* @return {Promise} Promise resolving when click occurs.
*/
async function clickBelow( elementHandle ) {
async function clickAtBottom( elementHandle ) {
const box = await elementHandle.boundingBox();
const x = box.x + ( box.width / 2 );
const y = box.y + box.height + 100;
const y = box.y + box.height - 50;
return page.mouse.click( x, y );
}

it( 'Should insert content using the placeholder and the regular inserter', async () => {
// This ensures the editor is loaded in navigation mode.
await page.reload();

// Set a tall viewport. The typewriter's intrinsic height can be enough
// to scroll the page on a shorter viewport, thus obscuring the presence
// of any potential buggy behavior with the "stretched" click redirect.
await setBrowserViewport( { width: 960, height: 1400 } );

// Click below editor to focus last field (block appender)
await clickBelow( await page.$( '.block-editor-default-block-appender' ) );
await clickAtBottom( await page.$( '.edit-post-editor-regions__content' ) );
expect( await page.$( '[data-type="core/paragraph"]' ) ).not.toBeNull();
await page.keyboard.type( 'Paragraph block' );

Expand Down
5 changes: 5 additions & 0 deletions packages/edit-post/src/components/editor-regions/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
.edit-post-editor-regions__content {
flex-grow: 1;

// Treat as flex container to allow children to grow to occupy full
// available height of the content area.
display: flex;
flex-direction: column;

// On Mobile the header is fixed to keep HTML as scrollable.
@include break-medium() {
overflow: auto;
Expand Down
8 changes: 7 additions & 1 deletion packages/edit-post/src/components/visual-editor/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@
}
}

.edit-post-visual-editor > .block-editor__typewriter,
.edit-post-visual-editor > .block-editor__typewriter > .block-editor-writing-flow,
.edit-post-visual-editor > .block-editor__typewriter > .block-editor-writing-flow > .block-editor-writing-flow__click-redirect {
height: 100%;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that .block-editor-writing-flow__click-redirect is smaller than .block-editor-writing-flow, taking into account the rest of the content, even though it's set to 100%. How does this work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that .block-editor-writing-flow__click-redirect is smaller than .block-editor-writing-flow, taking into account the rest of the content, even though it's set to 100%. How does this work?

If I understand correctly:

.block-editor-writing-flow is a flex container. I recall that in the past, it was very specifically implemented that the click redirect have a base height to occupy the full space, shrinking if necessary. I think those specific shrink styles might have since been removed, but apparently it still works? I might want to do a round of cross-browser testing, and perhaps add back that attribute just to be explicit.

}

.edit-post-visual-editor .block-editor-writing-flow__click-redirect {
// Allow the page to be scrolled with the last block in the middle.
height: 50vh;
min-height: 50vh;
width: 100%;
}

Expand Down