@@ -8,6 +8,7 @@ import { defineElement } from '@umbraco-ui/uui-base/lib/registration';
88import { demandCustomElement } from '@umbraco-ui/uui-base/lib/utils' ;
99import { css , html , LitElement } from 'lit' ;
1010import { property , state } from 'lit/decorators.js' ;
11+ import { ref } from 'lit/directives/ref.js' ;
1112import { ifDefined } from 'lit/directives/if-defined.js' ;
1213
1314import { UUIMenuItemEvent } from './UUIMenuItemEvent' ;
@@ -261,6 +262,10 @@ export class UUIMenuItemElement extends SelectOnlyMixin(
261262 @state ( )
262263 private iconSlotHasContent = false ;
263264
265+ labelButtonChanged ( label ?: Element | undefined ) {
266+ this . selectableTarget = label || this ;
267+ }
268+
264269 connectedCallback ( ) {
265270 super . connectedCallback ( ) ;
266271 if ( ! this . hasAttribute ( 'role' ) ) this . setAttribute ( 'role' , 'menu' ) ;
@@ -300,12 +305,13 @@ export class UUIMenuItemElement extends SelectOnlyMixin(
300305
301306 private _renderLabelAsAnchor ( ) {
302307 if ( this . disabled ) {
303- return html ` < span id ="label-button ">
308+ return html ` < span id ="label-button " ${ ref ( this . labelButtonChanged ) } >
304309 ${ this . _renderLabelInside ( ) }
305310 </ span > ` ;
306311 }
307312 return html ` < a
308313 id ="label-button "
314+ ${ ref ( this . labelButtonChanged ) }
309315 href =${ ifDefined ( this . href ) }
310316 target =${ ifDefined ( this . target || undefined ) }
311317 rel=${ ifDefined ( this . target === '_blank' ? 'noopener' : undefined ) }
@@ -319,6 +325,7 @@ export class UUIMenuItemElement extends SelectOnlyMixin(
319325 private _renderLabelAsButton ( ) {
320326 return html ` < button
321327 id ="label-button "
328+ ${ ref ( this . labelButtonChanged ) }
322329 @click =${ this . onLabelClicked }
323330 ?disabled =${ this . disabled }
324331 aria-label="${ this . label } ">
0 commit comments