1
1
import { LitElement , css , html } from 'lit' ;
2
- import { property } from 'lit/decorators.js' ;
2
+ import { property , state } from 'lit/decorators.js' ;
3
3
import {
4
4
ActiveMixin ,
5
5
LabelMixin ,
@@ -11,6 +11,13 @@ import { UUIMenuItemEvent } from './UUIMenuItemEvent';
11
11
* @element uui-menu-item
12
12
* @cssprop --uui-menu-item-indent - set indentation of the menu items
13
13
* @property label - This functions both as the visible label as well as the aria label.
14
+ * @fires {UUIMenuItemEvent } show-children - fires when the expand icon is clicked to show nested menu items
15
+ * @fires {UUIMenuItemEvent } hide-children - fires when the expend icon is clicked to hide nested menu items
16
+ * @fires {UUIMenuItemEvent } click-label - fires when the label is clicked
17
+ * @slot default slot for nested menu items
18
+ * @slot icon - icon area
19
+ * @slot actions - actions area
20
+ *
14
21
*/
15
22
export class UUIMenuItemElement extends SelectableMixin (
16
23
ActiveMixin ( LabelMixin ( 'label' , LitElement ) )
@@ -28,7 +35,7 @@ export class UUIMenuItemElement extends SelectableMixin(
28
35
position: relative;
29
36
display: flex;
30
37
align-items: stretch;
31
- padding-left: calc(var(--uui-menu-item-indent, 0) * var(--uui-size-8 ));
38
+ padding-left: calc(var(--uui-menu-item-indent, 0) * var(--uui-size-4 ));
32
39
33
40
display: grid;
34
41
grid-template-columns: var(--uui-size-8) 1fr;
@@ -62,9 +69,11 @@ export class UUIMenuItemElement extends SelectableMixin(
62
69
overflow: hidden;
63
70
text-overflow: ellipsis;
64
71
}
72
+
65
73
#caret-button + #label-button {
66
74
padding-left: 0;
67
75
}
76
+
68
77
#caret-button {
69
78
width: 100%;
70
79
height: 100%;
@@ -100,6 +109,13 @@ export class UUIMenuItemElement extends SelectableMixin(
100
109
bottom: 0;
101
110
}
102
111
112
+ #icon {
113
+ font-size: 16px;
114
+ margin-bottom: var(--uui-size-1);
115
+ margin-right: var(--uui-size-2);
116
+ display: inline-block;
117
+ }
118
+
103
119
:host([disabled]) #label-button {
104
120
color: var(--uui-interface-surface-contrast-disabled);
105
121
}
@@ -212,6 +228,24 @@ export class UUIMenuItemElement extends SelectableMixin(
212
228
private onLabelClicked ( ) {
213
229
const event = new UUIMenuItemEvent ( UUIMenuItemEvent . CLICK_LABEL ) ;
214
230
this . dispatchEvent ( event ) ;
231
+ this . toggleSelect ( ) ;
232
+ }
233
+
234
+ /**
235
+ * Toggles row selection
236
+ * @method
237
+ */
238
+ protected toggleSelect ( ) {
239
+ if ( this . selectable === false ) return ;
240
+ this . selected = ! this . selected ;
241
+ }
242
+
243
+ @state ( )
244
+ private iconSlotHasContent = false ;
245
+
246
+ private iconSlotChanged ( e : any ) : void {
247
+ this . iconSlotHasContent =
248
+ ( e . target as HTMLSlotElement ) . assignedNodes ( { flatten : true } ) . length > 0 ;
215
249
}
216
250
217
251
render ( ) {
@@ -227,6 +261,11 @@ export class UUIMenuItemElement extends SelectableMixin(
227
261
@click =${ this . onLabelClicked }
228
262
?disabled =${ this . disabled }
229
263
aria-label="${ this . label } ">
264
+ < slot
265
+ name ="icon "
266
+ id ="icon "
267
+ style =${ this . iconSlotHasContent ? '' : 'display: none;' }
268
+ @slotchange =${ this . iconSlotChanged } > </ slot >
230
269
${ this . renderLabel ( ) }
231
270
</ button >
232
271
< div id ="label-button-background "> </ div >
0 commit comments