@@ -51,6 +51,7 @@ export const BlockStylesControl = props => {
5151 const buttonRef = useRef ( null )
5252 const popoverOnCloseTimeout = useRef ( null )
5353 const popoverOnCloseRef = useRef ( false )
54+ const panelBodyRef = useRef ( null )
5455
5556 // Reset openProNotice when the popover is closed
5657 useEffect ( ( ) => {
@@ -159,11 +160,12 @@ export const BlockStylesControl = props => {
159160 size = "small"
160161 icon = "edit"
161162 iconSize = { 12 }
162- onClick = { ( ) => {
163- // Clicking this button when the popover is open also triggers the popover's `onClose`, so the popover will close automatically.
164- if ( ! openPopover && ! popoverOnCloseRef . current ) {
165- setOpenPopover ( true )
166- }
163+ onMouseDown = { ( ) => {
164+ setOpenPopover ( isOpen => ! isOpen )
165+ // Focus on the selected block style button when the popover is opened.
166+ setTimeout ( ( ) => {
167+ panelBodyRef . current ?. querySelector ( '.ugb-block-styles-controls__selected' ) ?. focus ( )
168+ } , 50 )
167169 } }
168170 ref = { buttonRef }
169171 >
@@ -192,7 +194,7 @@ export const BlockStylesControl = props => {
192194 { openPopover && (
193195 < Popover
194196 className = "ugb-button-icon-control__popover ugb-block-styles-controls__popover"
195- focusOnMount = "container"
197+ focusOnMount = { false }
196198 onEscape = { ( ) => setOpenPopover ( false ) }
197199 onClose = { ( ) => {
198200 setOpenPopover ( false )
@@ -206,7 +208,7 @@ export const BlockStylesControl = props => {
206208 placement = "left-start"
207209 resize = { false }
208210 >
209- < PanelBody >
211+ < PanelBody ref = { panelBodyRef } >
210212 < h2 className = "components-panel__body-title" > { __ ( 'Block Styles' , i18n ) } </ h2 >
211213 < p className = "components-panel__body-description" >
212214 { __ ( 'Choose a block style to quickly apply a predefined set of styles to this block.' , i18n ) }
0 commit comments