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

WIP: Move search block alignment from float to flex #31812

Closed
wants to merge 1 commit 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
3 changes: 3 additions & 0 deletions packages/block-library/src/search/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ export default function SearchEdit( {

{ showLabel && (
<RichText
style={ {
width: `${ width }${ widthUnit }`,
} }
className="wp-block-search__label"
aria-label={ __( 'Label text' ) }
placeholder={ __( 'Add label…' ) }
Expand Down
28 changes: 28 additions & 0 deletions packages/block-library/src/search/editor.scss
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
.wp-block[data-align="center"] {
.wp-block-search {
float: unset;
display: flex;
align-items: center;
flex-direction: column;
margin-left: 0;
.wp-block-search__inside-wrapper {
margin: auto;
}
}
}

.wp-block[data-align="right"] {
.wp-block-search {
float: unset;
display: flex;
align-items: flex-end;
flex-direction: column;
margin-left: 0;
}
.wp-block-search__label {
min-width: 220px !important;
Copy link
Contributor Author

@glendaviesnz glendaviesnz May 14, 2021

Choose a reason for hiding this comment

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

This is ugly, but the RichText component adds a minWidth of 1px as an inline style with no option to specify a custom width, if we go with this approach we should probably add a minWidth prop to this component, the native version has this. FYI, this min width setting is only needed to make right align work on 20% width.

}
}

.wp-block[data-align="left"] {
.wp-block-search {
float: unset;
display: flex;
align-items: flex-start;
flex-direction: column;
margin-left: 0;
}
}

.wp-block-search {
.wp-block-search__input {
padding: $grid-unit-10;
Expand Down
8 changes: 5 additions & 3 deletions packages/block-library/src/search/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ function render_block_core_search( $attributes ) {
if ( $show_label ) {
if ( ! empty( $attributes['label'] ) ) {
$label_markup = sprintf(
'<label for="%s" class="wp-block-search__label">%s</label>',
'<label for="%s" class="wp-block-search__label" %s>%s</label>',
$input_id,
$attributes['label']
$inline_styles['wrapper'],
$attributes['label'],
);
} else {
$label_markup = sprintf(
'<label for="%s" class="wp-block-search__label screen-reader-text">%s</label>',
'<label for="%s" class="wp-block-search__label screen-reader-text" %s>%s</label>',
$input_id,
$inline_styles['wrapper'],
__( 'Search' )
);
}
Expand Down
24 changes: 24 additions & 0 deletions packages/block-library/src/search/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@
}
}

&.alignright {
float: unset;
display: flex;
align-items: flex-end;
flex-direction: column;
margin-left: 0;
}

&.alignleft {
float: unset;
display: flex;
align-items: flex-start;
flex-direction: column;
margin-left: 0;
}

&.aligncenter {
float: unset;
display: flex;
align-items: center;
flex-direction: column;
margin-left: 0;
}

.wp-block-search__inside-wrapper {
display: flex;
flex: auto;
Expand Down