Skip to content

Commit

Permalink
fix(menu-button): allow single item (#2242)
Browse files Browse the repository at this point in the history
  • Loading branch information
LuLaValva authored Aug 30, 2024
1 parent 81a3106 commit 155233f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/beige-sloths-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ebay/ebayui-core": patch
---

Menu button single item fix
8 changes: 3 additions & 5 deletions src/common/menu-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface MenuItem extends Omit<Marko.Input<"button">, `on${string}`> {
}

export interface BaseMenuInput {
items?: Marko.RepeatableAttrTag<MenuItem>;
items?: Marko.RepeatableAttrTag<MenuItem> | [Marko.AttrTag<MenuItem>];
type?: string;
}

Expand Down Expand Up @@ -59,9 +59,7 @@ export class MenuUtils<
from items to pass correct indexes to state
Any other component that doesn't have separator should pass through
*/
this.items = ((input.items as Marko.AttrTag<MenuItem>[]) || []).filter(
(item) => !item.separator,
);
this.items = [...(input.items || [])].filter((item) => !item.separator);
this.type = input.type;
if (this.isRadio()) {
return {
Expand Down Expand Up @@ -110,7 +108,7 @@ export class MenuUtils<

getSeparatorMap(input: Input) {
let separatorCount = 0;
return ((input.items as MenuItem[]) || []).reduce(
return [...(input.items || [])].reduce(
(map, item, index) => {
if (item.separator) {
map[index - separatorCount] = true;
Expand Down

0 comments on commit 155233f

Please sign in to comment.