Skip to content

Commit

Permalink
feat: add className property for adding CSS classes to menu-bar items (
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoCardoso authored Oct 11, 2023
1 parent af30824 commit 677d037
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/menu-bar/src/vaadin-menu-bar-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ export const MenuBarMixin = (superClass) =>
button.textContent = item.text;
}

if (item.className) {
button.className = item.className;
}

return button;
}

Expand Down
9 changes: 8 additions & 1 deletion packages/menu-bar/src/vaadin-menu-bar.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export interface MenuBarItem {
* Array of submenu items.
*/
children?: SubMenuItem[];

/**
* Class/classes to be set to the class attribute of the button.
*/
className?: string;
}

export interface SubMenuItem {
Expand All @@ -43,6 +48,7 @@ export interface SubMenuItem {
disabled?: boolean;
theme?: string[] | string;
checked?: boolean;
className?: string;
children?: SubMenuItem[];
}

Expand Down Expand Up @@ -119,8 +125,9 @@ declare class MenuBar extends MenuBarMixin(DisabledMixin(ElementMixin(ThemableMi
* menubar.items = [
* {
* text: 'File',
* className: 'file',
* children: [
* {text: 'Open'}
* {text: 'Open', className: 'file open'}
* {text: 'Auto Save', checked: true},
* ]
* },
Expand Down
3 changes: 2 additions & 1 deletion packages/menu-bar/src/vaadin-menu-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ class MenuBar extends MenuBarMixin(DisabledMixin(ElementMixin(ThemableMixin(Poly
* menubar.items = [
* {
* text: 'File',
* className: 'file',
* children: [
* {text: 'Open'}
* {text: 'Open', className: 'file open'}
* {text: 'Auto Save', checked: true},
* ]
* },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const snapshots = {};
snapshots["menu-bar basic"] =
`<vaadin-menu-bar role="menubar">
<vaadin-menu-bar-button
class="home"
role="menuitem"
tabindex="0"
>
Expand All @@ -26,6 +27,7 @@ snapshots["menu-bar basic"] =
Dashboard
</vaadin-menu-bar-button>
<vaadin-menu-bar-button
class="help"
role="menuitem"
tabindex="0"
>
Expand Down Expand Up @@ -76,6 +78,7 @@ snapshots["menu-bar overlay"] =
<vaadin-menu-bar-item
aria-haspopup="false"
aria-selected="false"
class="generate reports"
role="menuitem"
tabindex="-1"
>
Expand Down Expand Up @@ -113,6 +116,7 @@ snapshots["menu-bar overlay class"] =
<vaadin-menu-bar-item
aria-haspopup="false"
aria-selected="false"
class="generate reports"
role="menuitem"
tabindex="-1"
>
Expand Down
5 changes: 3 additions & 2 deletions packages/menu-bar/test/dom/menu-bar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ describe('menu-bar', () => {
beforeEach(async () => {
menu = fixtureSync('<vaadin-menu-bar></vaadin-menu-bar>');
menu.items = [
{ text: 'Home' },
{ text: 'Home', className: 'home' },
{
text: 'Reports',
children: [{ text: 'View Reports' }, { text: 'Generate Report' }],
children: [{ text: 'View Reports' }, { text: 'Generate Report', className: 'reports generate' }],
},
{ text: 'Dashboard', disabled: true },
{
Expand All @@ -29,6 +29,7 @@ describe('menu-bar', () => {
item.appendChild(bold);
return item;
})(),
className: 'help',
},
];
await nextRender();
Expand Down

0 comments on commit 677d037

Please sign in to comment.