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

Default Block Appender: Remove redundant event handlers #8714

Merged
merged 1 commit into from
Aug 15, 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
15 changes: 13 additions & 2 deletions packages/editor/src/components/default-block-appender/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ export function DefaultBlockAppender( {

const value = decodeEntities( placeholder ) || __( 'Write your story' );

// The appender "button" is in-fact a text field so as to support
// transitions by WritingFlow occurring by arrow key press. WritingFlow
// only supports tab transitions into text fields and to the block focus
// boundary.
//
// See: https://github.com/WordPress/gutenberg/issues/4829#issuecomment-374213658
//
// If it were ever to be made to be a proper `button` element, it is
// important to note that `onFocus` alone would not be sufficient to
// capture click events, notably in Firefox.
//
// See: https://gist.github.com/cvrebert/68659d0333a578d75372

return (
<div
data-root-client-id={ rootClientId || '' }
Expand All @@ -51,8 +64,6 @@ export function DefaultBlockAppender( {
type="text"
readOnly
onFocus={ onAppend }
onClick={ onAppend }
onKeyDown={ onAppend }
value={ showPrompt ? value : '' }
/>
<InserterWithShortcuts rootClientId={ rootClientId } layout={ layout } />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ exports[`DefaultBlockAppender should append a default block when input focused 1
<input
aria-label="Add block"
className="editor-default-block-appender__content"
onClick={
[MockFunction] {
"calls": Array [
Array [],
],
"results": undefined,
}
}
onFocus={
[MockFunction] {
"calls": Array [
Expand All @@ -25,14 +17,6 @@ exports[`DefaultBlockAppender should append a default block when input focused 1
"results": undefined,
}
}
onKeyDown={
[MockFunction] {
"calls": Array [
Array [],
],
"results": undefined,
}
}
readOnly={true}
role="button"
type="text"
Expand Down Expand Up @@ -60,9 +44,7 @@ exports[`DefaultBlockAppender should match snapshot 1`] = `
<input
aria-label="Add block"
className="editor-default-block-appender__content"
onClick={[MockFunction]}
onFocus={[MockFunction]}
onKeyDown={[MockFunction]}
readOnly={true}
role="button"
type="text"
Expand Down Expand Up @@ -90,9 +72,7 @@ exports[`DefaultBlockAppender should optionally show without prompt 1`] = `
<input
aria-label="Add block"
className="editor-default-block-appender__content"
onClick={[MockFunction]}
onFocus={[MockFunction]}
onKeyDown={[MockFunction]}
readOnly={true}
role="button"
type="text"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ describe( 'DefaultBlockAppender', () => {
expect( wrapper ).toMatchSnapshot();
} );

it( 'should append a default block when input clicked', () => {
const onAppend = jest.fn();
const wrapper = shallow( <DefaultBlockAppender isVisible onAppend={ onAppend } showPrompt /> );
const input = wrapper.find( 'input.editor-default-block-appender__content' );

expect( input.prop( 'value' ) ).toEqual( 'Write your story' );
input.simulate( 'click' );

expectOnAppendCalled( onAppend );
} );

it( 'should append a default block when input focused', () => {
const onAppend = jest.fn();
const wrapper = shallow( <DefaultBlockAppender isVisible onAppend={ onAppend } showPrompt /> );
Expand Down