Skip to content

Commit 4ef110c

Browse files
authored
Show a pointer/hint in the settings tab informing the user about the styles tab (#47670)
* Show a pointer/hint in the settings tab informing the user about the styles tab * Add a spoken message when the notice is dismissed * Update margin around text and button * Remove spoken message * Rename to hint and add focus management code * Relabel dismiss button
1 parent 4f94f09 commit 4ef110c

File tree

5 files changed

+76
-0
lines changed

5 files changed

+76
-0
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/block-editor/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"@wordpress/keyboard-shortcuts": "file:../keyboard-shortcuts",
5555
"@wordpress/keycodes": "file:../keycodes",
5656
"@wordpress/notices": "file:../notices",
57+
"@wordpress/preferences": "file:../preferences",
5758
"@wordpress/rich-text": "file:../rich-text",
5859
"@wordpress/shortcode": "file:../shortcode",
5960
"@wordpress/style-engine": "file:../style-engine",
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* WordPress dependencies
3+
*/
4+
import { Button } from '@wordpress/components';
5+
import { useDispatch, useSelect } from '@wordpress/data';
6+
import { focus } from '@wordpress/dom';
7+
import { useRef } from '@wordpress/element';
8+
import { __ } from '@wordpress/i18n';
9+
import { close } from '@wordpress/icons';
10+
import { store as preferencesStore } from '@wordpress/preferences';
11+
12+
const PREFERENCE_NAME = 'isInspectorControlsTabsHintVisible';
13+
14+
export default function InspectorControlsTabsHint() {
15+
const isInspectorControlsTabsHintVisible = useSelect(
16+
( select ) =>
17+
select( preferencesStore ).get( 'core', PREFERENCE_NAME ) ?? true,
18+
[]
19+
);
20+
21+
const ref = useRef();
22+
23+
const { set: setPreference } = useDispatch( preferencesStore );
24+
if ( ! isInspectorControlsTabsHintVisible ) {
25+
return null;
26+
}
27+
28+
return (
29+
<div ref={ ref } className="block-editor-inspector-controls-tabs__hint">
30+
<div className="block-editor-inspector-controls-tabs__hint-content">
31+
{ __(
32+
"Looking for other block settings? They've moved to the styles tab."
33+
) }
34+
</div>
35+
<Button
36+
className="block-editor-inspector-controls-tabs__hint-dismiss"
37+
icon={ close }
38+
iconSize="16"
39+
label={ __( 'Dismiss hint' ) }
40+
onClick={ () => {
41+
// Retain focus when dismissing the element.
42+
const previousElement = focus.tabbable.findPrevious(
43+
ref.current
44+
);
45+
previousElement?.focus();
46+
setPreference( 'core', PREFERENCE_NAME, false );
47+
} }
48+
showTooltip={ false }
49+
/>
50+
</div>
51+
);
52+
}

packages/block-editor/src/components/inspector-controls-tabs/settings-tab.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import AdvancedControls from './advanced-controls-panel';
55
import PositionControls from './position-controls-panel';
66
import { default as InspectorControls } from '../inspector-controls';
7+
import SettingsTabHint from './settings-tab-hint';
78

89
const SettingsTab = ( { showAdvancedControls = false } ) => (
910
<>
@@ -14,6 +15,7 @@ const SettingsTab = ( { showAdvancedControls = false } ) => (
1415
<AdvancedControls />
1516
</div>
1617
) }
18+
<SettingsTabHint />
1719
</>
1820
);
1921

packages/block-editor/src/components/inspector-controls-tabs/style.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,23 @@
1313
}
1414
}
1515
}
16+
17+
.block-editor-inspector-controls-tabs__hint {
18+
align-items: top;
19+
background: $gray-100;
20+
border-radius: $radius-block-ui;
21+
color: $gray-900;
22+
display: flex;
23+
flex-direction: row;
24+
margin: $grid-unit-20;
25+
}
26+
27+
.block-editor-inspector-controls-tabs__hint-content {
28+
margin: $grid-unit-15 0 $grid-unit-15 $grid-unit-15;
29+
}
30+
31+
.block-editor-inspector-controls-tabs__hint-dismiss {
32+
// The dismiss button has a lot of empty space through its padding.
33+
// Apply margin to visually align the icon with the top of the text to its left.
34+
margin: $grid-unit-05 $grid-unit-05 $grid-unit-05 0;
35+
}

0 commit comments

Comments
 (0)