Skip to content

Commit cc42d27

Browse files
jasmussendonnapep
authored andcommitted
Improve the navigation block setup state / placeholder. (#31371)
* Initial refactor. - Bring back Placeholder component for responsiveness. - Unstyle some things. - Tweak placeholder skeleton to inherit styles and match height of actual menu items. * Fix onselect jump. * Improve responsiveness. * Final polish. * Update test. * Don't wrap. * Remove transition. * Fix for navigation screen empty state. * Fix display.
1 parent af98f10 commit cc42d27

File tree

5 files changed

+69
-39
lines changed

5 files changed

+69
-39
lines changed

packages/block-library/src/navigation/editor.scss

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,22 @@ $color-control-label-height: 20px;
165165
* Setup state
166166
*/
167167

168-
// Ensure that an empty block has space around the appender.
169-
.wp-block-navigation-placeholder,
170-
.wp-block-navigation-placeholder__preview,
171-
.is-selected .wp-block-navigation__container {
172-
min-height: $grid-unit-05 + $grid-unit-05 + $button-size;
168+
// Unstyle some inherited placeholder component styles.
169+
.components-placeholder.wp-block-navigation-placeholder {
170+
outline: none;
171+
padding: 0;
172+
box-shadow: none;
173+
background: none;
174+
min-height: 0;
175+
176+
// Needed for the preview menu items to match actual menu items.
177+
.components-placeholder__fieldset {
178+
font-size: inherit;
179+
}
180+
181+
.components-placeholder__fieldset .components-button {
182+
margin-bottom: 0;
183+
}
173184
}
174185

175186
// Spinner.
@@ -185,17 +196,24 @@ $color-control-label-height: 20px;
185196
display: flex;
186197
flex-direction: row;
187198
align-items: center;
188-
transition: all 0.1s ease-in-out;
189-
@include reduce-motion("transition");
199+
flex-wrap: nowrap;
200+
width: 100%;
201+
overflow: hidden;
190202

191-
// Style skeleton elements.
203+
// Style skeleton elements to mostly match the metrics of actual menu items.
192204
// Needs specificity.
193205
.wp-block-navigation-link.wp-block-navigation-link {
194-
border-radius: $radius-block-ui;
195-
background: currentColor;
206+
position: relative;
196207
min-width: 72px;
197-
height: $grid-unit-20;
198-
margin: $grid-unit-15 $grid-unit-30 $grid-unit-15 0;
208+
209+
&::before {
210+
display: block;
211+
content: "";
212+
border-radius: $radius-block-ui;
213+
background: currentColor;
214+
height: $grid-unit-20;
215+
width: 100%;
216+
}
199217
}
200218

201219
svg {
@@ -207,22 +225,25 @@ $color-control-label-height: 20px;
207225
opacity: 0.3;
208226
}
209227

210-
.is-selected & {
211-
// Don't show the preview boxes for an empty nav block.
212-
opacity: 0;
228+
// Don't show the preview boxes for an empty nav block.
229+
// Needs specificity to work for the navigation screen.
230+
.wp-block-navigation.is-selected &.wp-block-navigation-placeholder__preview {
231+
display: none;
232+
}
213233

214-
// Need to show the placeholder box above the preview boxes.
215-
position: absolute;
216-
top: 0;
217-
right: 0;
218-
bottom: 0;
219-
left: 0;
234+
// ... but be present in larger contexts to size it correctly.
235+
.wp-block-navigation.is-selected .is-large & {
236+
display: flex;
237+
opacity: 0;
238+
width: 0;
239+
overflow: hidden;
240+
flex-wrap: nowrap;
220241
}
221242
}
222243

223244
// Selected state.
224245
.wp-block-navigation-placeholder__controls {
225-
padding: $grid-unit-05 $grid-unit-10;
246+
padding: $grid-unit-10;
226247
border-radius: $radius-block-ui;
227248
background-color: $white;
228249
box-shadow: inset 0 0 0 $border-width $gray-900;
@@ -232,18 +253,25 @@ $color-control-label-height: 20px;
232253
position: relative;
233254
z-index: 1;
234255

256+
// Adjust padding for when shown horizontally.
257+
.is-large & {
258+
padding: $grid-unit-05 $grid-unit-10;
259+
}
260+
235261
// If an ancestor has a text-decoration property applied, it is inherited regardless of
236262
// the specificity of a child element. Only pulling the child out of the flow fixes it.
237263
// See also https://www.w3.org/TR/CSS21/text.html#propdef-text-decoration.
238264
float: left;
239265
width: 100%;
240266

241267
// Show when selected.
242-
.is-selected & {
268+
.wp-block-navigation.is-selected & {
243269
display: flex;
244270
}
245271

246-
// Vertical navigation.
272+
// Show stacked for the vertical navigation, or small placeholders.
273+
.is-small &,
274+
.is-medium &,
247275
.is-vertical & {
248276
.wp-block-navigation-placeholder__actions {
249277
flex-direction: column;
@@ -263,13 +291,12 @@ $color-control-label-height: 20px;
263291
// Block title
264292
.wp-block-navigation-placeholder__actions__indicator {
265293
margin-right: $grid-unit-15;
266-
padding: ($grid-unit-15 / 2) 0;
294+
padding: 0;
267295
align-items: center;
268296
justify-content: flex-start;
269-
display: none;
270297
line-height: 0;
271298

272-
// line up with the icon in the toolbar.
299+
// Line up with the icon in the toolbar.
273300
margin-left: $grid-unit-05 + $border-width;
274301

275302
svg {
@@ -281,7 +308,9 @@ $color-control-label-height: 20px;
281308
margin-left: 0;
282309
}
283310

284-
@include break-small {
311+
// Show only in big placeholders.
312+
display: none;
313+
.is-large & {
285314
display: inline-flex;
286315
}
287316
}

packages/block-library/src/navigation/placeholder-preview.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import { Icon, search } from '@wordpress/icons';
55

66
const PlaceholderPreview = () => {
77
return (
8-
<div className="wp-block-navigation-placeholder__preview">
9-
<span className="wp-block-navigation-link"></span>
10-
<span className="wp-block-navigation-link"></span>
11-
<span className="wp-block-navigation-link"></span>
8+
<ul className="wp-block-navigation-placeholder__preview wp-block-navigation__container">
9+
<li className="wp-block-navigation-link">&#8203;</li>
10+
<li className="wp-block-navigation-link">&#8203;</li>
11+
<li className="wp-block-navigation-link">&#8203;</li>
1212
<Icon icon={ search } />
13-
</div>
13+
</ul>
1414
);
1515
};
1616

packages/block-library/src/navigation/placeholder.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
import { createBlock } from '@wordpress/blocks';
55
import {
6+
Placeholder,
67
Button,
78
DropdownMenu,
89
MenuGroup,
@@ -162,7 +163,7 @@ function NavigationPlaceholder( { onCreate }, ref ) {
162163
className: 'wp-block-navigation-placeholder__actions__dropdown',
163164
};
164165
return (
165-
<div className="wp-block-navigation-placeholder">
166+
<Placeholder className="wp-block-navigation-placeholder">
166167
<PlaceholderPreview />
167168

168169
<div className="wp-block-navigation-placeholder__controls">
@@ -181,7 +182,7 @@ function NavigationPlaceholder( { onCreate }, ref ) {
181182
</div>
182183
{ hasMenus ? (
183184
<DropdownMenu
184-
text={ __( 'Existing menu' ) }
185+
text={ __( 'Add existing menu' ) }
185186
icon={ chevronDown }
186187
toggleProps={ toggleProps }
187188
>
@@ -222,7 +223,7 @@ function NavigationPlaceholder( { onCreate }, ref ) {
222223
</div>
223224
) }
224225
</div>
225-
</div>
226+
</Placeholder>
226227
);
227228
}
228229

packages/components/src/placeholder/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ function Placeholder( {
4646
let modifierClassNames;
4747
if ( typeof width === 'number' ) {
4848
modifierClassNames = {
49-
'is-large': width >= 320,
50-
'is-medium': width >= 160 && width < 320,
49+
'is-large': width >= 480,
50+
'is-medium': width >= 160 && width < 480,
5151
'is-small': width < 160,
5252
};
5353
}

packages/components/src/placeholder/test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe( 'Placeholder', () => {
113113
it( 'should not assign modifier class in first-pass `null` width from `useResizeObserver`', () => {
114114
useResizeObserver.mockReturnValue( [
115115
<div key="1" />,
116-
{ width: 320 },
116+
{ width: 480 },
117117
] );
118118

119119
const placeholder = shallow( <Placeholder /> );

0 commit comments

Comments
 (0)