Skip to content

Commit 31b2d97

Browse files
committed
chore(menu): add readonly modifier to immutable class members
Added readonly to every arrow-function property in menu that doesn’t get reassigned.
1 parent eecb117 commit 31b2d97

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

src/components/menu/menu.tsx

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ export class Menu {
293293
return breadCrumbItems.reverse();
294294
}
295295

296-
private renderLoader = () => {
296+
private readonly renderLoader = () => {
297297
if (!this.loadingSubItems && !this.loading) {
298298
return;
299299
}
@@ -315,7 +315,7 @@ export class Menu {
315315
);
316316
};
317317

318-
private renderBreadcrumb = () => {
318+
private readonly renderBreadcrumb = () => {
319319
const breadcrumbsItems = this.getBreadcrumbsItems();
320320
if (breadcrumbsItems.length === 0) {
321321
return;
@@ -351,7 +351,7 @@ export class Menu {
351351
this.handleSelect(event.detail.menuItem);
352352
};
353353

354-
private renderSearchField = () => {
354+
private readonly renderSearchField = () => {
355355
if (!this.searcher) {
356356
return;
357357
}
@@ -373,7 +373,7 @@ export class Menu {
373373
);
374374
};
375375

376-
private renderEmptyMessage = () => {
376+
private readonly renderEmptyMessage = () => {
377377
if (
378378
this.loading ||
379379
this.loadingSubItems ||
@@ -396,7 +396,7 @@ export class Menu {
396396
);
397397
};
398398

399-
private renderMenuList = () => {
399+
private readonly renderMenuList = () => {
400400
let items = this.visibleItems;
401401

402402
if (this.loadingSubItems || this.loading) {
@@ -421,7 +421,7 @@ export class Menu {
421421
);
422422
};
423423

424-
private handleTextInput = async (
424+
private readonly handleTextInput = async (
425425
event: LimelInputFieldCustomEvent<string>
426426
) => {
427427
event.stopPropagation();
@@ -450,7 +450,7 @@ export class Menu {
450450
// Key handler for the input search field
451451
// Will change focus to breadcrumbs (if present) or the first/last item
452452
// in the dropdown list to enable selection with the keyboard
453-
private handleInputKeyDown = (event: KeyboardEvent) => {
453+
private readonly handleInputKeyDown = (event: KeyboardEvent) => {
454454
const isForwardTab =
455455
event.key === TAB &&
456456
!event.altKey &&
@@ -528,7 +528,7 @@ export class Menu {
528528
// Key handler for the menu list (bubble phase)
529529
// Will change focus to the search field if using shift+tab
530530
// And can go forward/back with right/left arrow keys
531-
private handleMenuKeyDown = (event: KeyboardEvent) => {
531+
private readonly handleMenuKeyDown = (event: KeyboardEvent) => {
532532
const isBackwardTab =
533533
event.key === TAB &&
534534
!event.altKey &&
@@ -566,7 +566,7 @@ export class Menu {
566566
// Key handler for breadcrumbs
567567
// Up arrow: focus search input
568568
// Down arrow: focus first list item
569-
private handleBreadcrumbsKeyDown = (event: KeyboardEvent) => {
569+
private readonly handleBreadcrumbsKeyDown = (event: KeyboardEvent) => {
570570
const isUp = event.key === ARROW_UP;
571571
const isDown = event.key === ARROW_DOWN;
572572

@@ -588,7 +588,7 @@ export class Menu {
588588
}
589589
};
590590

591-
private clearSearch = () => {
591+
private readonly clearSearch = () => {
592592
this.searchValue = '';
593593
this.searchResults = null;
594594
this.loadingSubItems = false;
@@ -619,11 +619,11 @@ export class Menu {
619619
return (item ?? this.visibleItems[0]) as MenuItem;
620620
};
621621

622-
private goForward = (currentItem: MenuItem) => {
622+
private readonly goForward = (currentItem: MenuItem) => {
623623
this.handleSelect(currentItem, false);
624624
};
625625

626-
private goBack = () => {
626+
private readonly goBack = () => {
627627
if (!this.currentSubMenu) {
628628
// Already in the root of the menu
629629
return;
@@ -645,7 +645,7 @@ export class Menu {
645645
this.handleSelect(parent);
646646
};
647647

648-
private setTriggerAttributes = (element: HTMLElement) => {
648+
private readonly setTriggerAttributes = (element: HTMLElement) => {
649649
const attributes = {
650650
'aria-haspopup': true,
651651
'aria-expanded': this.open,
@@ -663,13 +663,13 @@ export class Menu {
663663
}
664664
};
665665

666-
private onClose = () => {
666+
private readonly onClose = () => {
667667
this.cancel.emit();
668668
this.open = false;
669669
this.currentSubMenu = null;
670670
};
671671

672-
private onTriggerClick = (event: MouseEvent) => {
672+
private readonly onTriggerClick = (event: MouseEvent) => {
673673
event.stopPropagation();
674674
if (this.disabled) {
675675
return;
@@ -678,7 +678,7 @@ export class Menu {
678678
this.open = !this.open;
679679
};
680680

681-
private handleSelect = async (
681+
private readonly handleSelect = async (
682682
menuItem: MenuItem,
683683
selectOnEmptyChildren: boolean = true
684684
) => {
@@ -728,7 +728,7 @@ export class Menu {
728728
this.setFocus();
729729
};
730730

731-
private onSelect = (event: CustomEvent<MenuItem>) => {
731+
private readonly onSelect = (event: CustomEvent<MenuItem>) => {
732732
event.stopPropagation();
733733
this.handleSelect(event.detail);
734734
};
@@ -752,7 +752,7 @@ export class Menu {
752752
return zipObject(propertyNames, values) as Record<PropName, string>;
753753
}
754754

755-
private setListElement = (element: HTMLLimelMenuListElement) => {
755+
private readonly setListElement = (element: HTMLLimelMenuListElement) => {
756756
if (this.list) {
757757
this.list.removeEventListener(
758758
'keydown',
@@ -772,7 +772,7 @@ export class Menu {
772772
}
773773
};
774774

775-
private setFocus = () => {
775+
private readonly setFocus = () => {
776776
setTimeout(() => {
777777
if (this.searchInput && this.searcher) {
778778
const observer = new IntersectionObserver(() => {
@@ -794,7 +794,9 @@ export class Menu {
794794
}, 0);
795795
};
796796

797-
private setSearchElement = (element: HTMLLimelInputFieldElement) => {
797+
private readonly setSearchElement = (
798+
element: HTMLLimelInputFieldElement
799+
) => {
798800
this.searchInput = element;
799801
};
800802

@@ -902,16 +904,16 @@ export class Menu {
902904
return !('separator' in item);
903905
}
904906

905-
private renderNotificationBadge = () => {
907+
private readonly renderNotificationBadge = () => {
906908
if (this.items.some(this.hasNotificationBadge)) {
907909
return <limel-badge />;
908910
}
909911
};
910912

911-
private hasNotificationBadge = (item: MenuItem | ListSeparator) =>
913+
private readonly hasNotificationBadge = (item: MenuItem | ListSeparator) =>
912914
this.isMenuItem(item) && item.badge !== undefined;
913915

914-
private setTriggerRef = (elm?: HTMLSlotElement) => {
916+
private readonly setTriggerRef = (elm?: HTMLSlotElement) => {
915917
this.triggerElement = elm;
916918
};
917919

0 commit comments

Comments
 (0)