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

Make the search block editor match the frontend #30176

Closed
wants to merge 3 commits into from
Closed
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: 0 additions & 1 deletion packages/block-library/src/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
@import "./pullquote/editor.scss";
@import "./quote/editor.scss";
@import "./rss/editor.scss";
@import "./search/editor.scss";
@import "./separator/editor.scss";
@import "./shortcode/editor.scss";
@import "./site-logo/editor.scss";
Expand Down
48 changes: 48 additions & 0 deletions packages/block-library/src/reset.scss
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,52 @@
line-height: revert;
font-weight: revert;
}

select,
input,
textarea,
button {
font-family: system-ui;
font-size: revert;
font-weight: revert;
border-radius: revert;
border: revert;
background: revert;
color: revert;
padding: revert;
margin: revert;
line-height: revert;
min-height: revert;
box-shadow: revert;
box-sizing: revert;
}

// For these I prefer to only override the WP-Admin defined styles and not "all"
// To minimize the risk to impact block styles as much as possible.
input[type="checkbox"],
input[type="color"],
input[type="date"],
input[type="datetime-local"],
input[type="datetime"],
input[type="email"],
input[type="month"],
input[type="number"],
input[type="password"],
input[type="radio"],
input[type="search"],
input[type="tel"],
input[type="text"],
input[type="time"],
input[type="url"],
input[type="week"],
input,
select,
textarea {
&:focus {
border: revert;
box-shadow: revert;
outline: revert;
padding: revert;
}
}
}
26 changes: 16 additions & 10 deletions packages/block-library/src/search/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export default function SearchEdit( {
const renderTextField = () => {
return (
<input
type="search"
className="wp-block-search__input"
aria-label={ __( 'Optional placeholder text' ) }
// We hide the placeholder field's placeholder when there is a value. This
Expand Down Expand Up @@ -148,16 +149,21 @@ export default function SearchEdit( {
) }

{ ! buttonUseIcon && (
<RichText
className="wp-block-search__button"
aria-label={ __( 'Button text' ) }
placeholder={ __( 'Add button text…' ) }
withoutInteractiveFormatting
value={ buttonText }
onChange={ ( html ) =>
setAttributes( { buttonText: html } )
}
/>
// This rule only makes sense for UI not blocks.
// eslint-disable-next-line react/forbid-elements
<button type="submit" className="wp-block-search__button">
<RichText
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems there's something that prevents RichText from working as a "button". I've used a small hack here to make it work and still keep a similar markup to the frontend.

Copy link
Member

Choose a reason for hiding this comment

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

What prevents it from working? Do you get any errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just stuck, like you can't edit it. Maybe "contenteditable" doesn't work on buttons?

Copy link
Member

Choose a reason for hiding this comment

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

That's interesting. I'll try this out in a bit.

Copy link
Member

Choose a reason for hiding this comment

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

It should work: https://codepen.io/iseulde/pen/vYgOpVw

Maybe something is wrong in RichText.

Copy link
Member

Choose a reason for hiding this comment

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

For some reason the selection change event is not firing in this context. It is in codepen though. Strange.

Copy link
Member

Choose a reason for hiding this comment

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

It seems something is the block editor is causing the issue. I insert <button contenteditable>test</button> without rich text in a block and it also fails to set selection. The same line on an empty web page works fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ellatrix after the removal of revert: all, I have two bugs:

  • In safari, backspace removes the block and not a character in the text
  • in chrome, I can't type an empty space

Copy link
Member

Choose a reason for hiding this comment

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

Hm, yes, Space will conflict with "pressing" the button.
I'll have a look at both issues. In the meantime, feel free to nest it in a span and we can adjust later.

tagName="span"
style={ { display: 'inline-block' } }
aria-label={ __( 'Button text' ) }
placeholder={ __( 'Add button text…' ) }
withoutInteractiveFormatting
value={ buttonText }
onChange={ ( html ) =>
setAttributes( { buttonText: html } )
}
/>
</button>
) }
</>
);
Expand Down
24 changes: 0 additions & 24 deletions packages/block-library/src/search/editor.scss

This file was deleted.