-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
feat: Focus title if title is empty #9608
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d92a85d
feat: Focus title when empty
tofumatt e20aa13
chore: Tweak comments/code clarity
tofumatt 0f58977
chore: PR Tweaks
tofumatt ce5e741
feat: Use autofocus and improve tests
tofumatt 13b6d43
chore: Use autoFocus prop and isCleanNewPost selector
tofumatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { newPost } from '../support/utils'; | ||
|
||
describe( 'new editor state', () => { | ||
beforeAll( async () => { | ||
await newPost(); | ||
} ); | ||
|
||
it( 'should show the New Post page in Gutenberg', async () => { | ||
expect( page.url() ).toEqual( expect.stringContaining( 'post-new.php' ) ); | ||
// Should display the title. | ||
const title = await page.$( '[placeholder="Add title"]' ); | ||
expect( title ).not.toBeNull(); | ||
// Should display the Preview button. | ||
const postPreviewButton = await page.$( '.editor-post-preview.components-button' ); | ||
expect( postPreviewButton ).not.toBeNull(); | ||
// Should display the Post Formats UI. | ||
const postFormatsUi = await page.$( '.editor-post-format' ); | ||
expect( postFormatsUi ).not.toBeNull(); | ||
} ); | ||
|
||
it( 'should have no history', async () => { | ||
const undoButton = await page.$( '.editor-history__undo:not( :disabled )' ); | ||
const redoButton = await page.$( '.editor-history__redo:not( :disabled )' ); | ||
|
||
expect( undoButton ).toBeNull(); | ||
expect( redoButton ).toBeNull(); | ||
} ); | ||
|
||
it( 'should focus the title if the title is empty', async () => { | ||
// We need to remove the tips to make sure they aren't clicked/removed | ||
// during our check of the title `textarea`'s focus. | ||
await page.evaluate( () => { | ||
return wp.data.dispatch( 'core/nux' ).disableTips(); | ||
} ); | ||
|
||
// And then reload the page to ensure we get a new page that should | ||
// autofocus the title, without any NUX tips. | ||
await page.reload(); | ||
|
||
const activeElementClasses = await page.evaluate( () => { | ||
return Object.values( document.activeElement.classList ); | ||
} ); | ||
const activeElementTagName = await page.evaluate( () => { | ||
return document.activeElement.tagName.toLowerCase(); | ||
} ); | ||
|
||
expect( activeElementClasses ).toContain( 'editor-post-title__input' ); | ||
expect( activeElementTagName ).toEqual( 'textarea' ); | ||
} ); | ||
|
||
it( 'should not focus the title if the title exists', async () => { | ||
// Enter a title for this post. | ||
await page.type( '.editor-post-title__input', 'Here is the title' ); | ||
// Save the post as a draft. | ||
await page.click( '.editor-post-save-draft' ); | ||
await page.waitForSelector( '.editor-post-saved-state.is-saved' ); | ||
// Reload the browser so a post is loaded with a title. | ||
await page.reload(); | ||
|
||
const activeElementClasses = await page.evaluate( () => { | ||
return Object.values( document.activeElement.classList ); | ||
} ); | ||
const activeElementTagName = await page.evaluate( () => { | ||
return document.activeElement.tagName.toLowerCase(); | ||
} ); | ||
|
||
expect( activeElementClasses ).not.toContain( 'editor-post-title__input' ); | ||
// The document `body` should be the `activeElement`, because nothing is | ||
// focused by default when a post already has a title. | ||
expect( activeElementTagName ).toEqual( 'body' ); | ||
} ); | ||
} ); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes are largely unrelated, but I forget why I found this file when working on this patch and just wanted to tidy things up. Sorry 😉