@@ -157,6 +157,14 @@ export class HoverPaneController implements HoverPaneControllerInterface {
157157 /** A record of the last mouse position on the host element, for positioning the hover pane */
158158 private lastPointerClientPos = { x : 0 , y : 0 } ;
159159
160+ /**
161+ * A flag to track whether the host element is being clicked by a pointer device, so that we
162+ * don't trigger unnecessary keyboard focus behaviors on click. This is needed, e.g., to prevent
163+ * the hover pane from appearing immediately at its `host` positioning on click, which can
164+ * obstruct the host element itself (due to the ordering of events fired).
165+ */
166+ private clicking = false ;
167+
160168 constructor (
161169 /** The host element to which this controller should attach listeners */
162170 private readonly host : ReactiveControllerHost &
@@ -352,6 +360,7 @@ export class HoverPaneController implements HoverPaneControllerInterface {
352360 // keyboard navigation listeners
353361 this . host . addEventListener ( 'focus' , this . handleFocus ) ;
354362 this . host . addEventListener ( 'blur' , this . handleBlur ) ;
363+ this . host . addEventListener ( 'pointerdown' , this . handlePointerDown ) ;
355364 this . host . addEventListener ( 'keyup' , this . handleKeyUp ) ;
356365 this . host . addEventListener ( 'keydown' , this . handleKeyDown ) ;
357366
@@ -391,11 +400,12 @@ export class HoverPaneController implements HoverPaneControllerInterface {
391400 }
392401
393402 private handleFocus = ( ) : void => {
394- if ( this . hoverPaneState === 'hidden' ) {
403+ if ( ! this . clicking && this . hoverPaneState === 'hidden' ) {
395404 this . showHoverPane ( {
396405 anchor : 'host' ,
397406 } ) ;
398407 }
408+ this . clicking = false ;
399409 } ;
400410
401411 private handleBlur = ( ) : void => {
@@ -404,6 +414,10 @@ export class HoverPaneController implements HoverPaneControllerInterface {
404414 }
405415 } ;
406416
417+ private handlePointerDown = ( ) : void => {
418+ this . clicking = true ;
419+ } ;
420+
407421 private handleKeyDown = ( e : KeyboardEvent ) : void => {
408422 if (
409423 ( e . key === 'ArrowDown' || e . key === 'ArrowUp' ) &&
0 commit comments