Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: theme property for individual menu items #2401

Merged
merged 8 commits into from
Sep 2, 2021

Conversation

eriklumme
Copy link

The vaadin-menu-bar as a whole is themable, and setting the theme attribute on it will propagate it to all menu bar buttons.
However, a user might want to add a theme to only some select buttons, for example to show one as the primary option. While
this can be done by supplying a component, it is not the most convenient approach, and the theme property is also needed
for the Java API.

Part of vaadin/flow-components#880.

Note: I am not sure if it's better to merge the themes of the menu-bar and the menu-bar-item, or if the menu-bar-item should override the former. Currently they are merged.

Merging makes sense to me, for example if you set primary on the menu-bar and special on one item, it will be primary special.

However, what if you wanted all but one to be primary? You can't remove the menu-bar theme by setting theme: '' on an item. And if you do something like theme: 'tertiary', the result will be primary tertiary, and the styles will be strange. So this requires you to customize the styles for that combination.

Thoughts?

Type of change

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs-beta/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

Additional for Feature type of change

  • Enhancement / new feature was discussed in a corresponding GitHub issue and Acceptance Criteria were created.

The vaadin-menu-bar as a whole is themable, and setting the theme attribute on it will propagate it to all menu bar buttons.
However, a user might want to add a theme to only some select buttons, for example to show one as the primary option. While
this can be done by supplying a component, it is not the most convenient approach, and the theme property is also needed
for the Java API. Part of vaadin/flow-components#880.
@eriklumme
Copy link
Author

FYI @yuriy-fix

Erik Lumme added 2 commits August 27, 2021 10:57
As the context menu used by vaadin-menu-bar propagates the parent element theme to context menu items,
a similar approach must be used here. Otherwise, whatever theme is manually set will be overridden.
@eriklumme
Copy link
Author

Thought I could get away without introducing the same for vaadin-context-menu, but I can't, as even though it's possible to set the theme on context menu items manually, it would be overridden by the context menu's propagation of the root element theme to child elements.

Copy link
Contributor

@yuriy-fix yuriy-fix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the PR description, I guess we should override theme coming from the parent.
It will work for cases when you want to have one tertiary button and others as primary
In addition, we can also provide an array / list of themes (themes:['error', 'primary']) for an item in that case.

The reason is that it won’t be easy to remove the theme from the child items and users will need to come up with CSS tricks in order to re-style the item with a weird combination of themes, like mentioned primary + tertiary

@eriklumme
Copy link
Author

eriklumme commented Sep 1, 2021

@web-padawan might want to take a look at the merge commit, that I'm not ruining his changes...
2a5dd61

(If you click Commits in this PR and the latest merge commit, it'll just show the conflict I resolved)

Comment on lines 59 to 68
this._buttons.forEach((button) => {
const itemTheme = this.__stringOrArrayToString(button.item && button.item.theme);
if (itemTheme) {
button.setAttribute('theme', itemTheme);
} else if (theme) {
button.setAttribute('theme', theme);
} else {
button.removeAttribute('theme');
}
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic should be removed from here as we now handle it in the other mixin - no need to duplicate.
So just removing the lines below should be enough (and only set sub menu theme).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, and the menu-bar tests in web-components and flow-components still pass, so looks good.

@sonarcloud
Copy link

sonarcloud bot commented Sep 2, 2021

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@web-padawan
Copy link
Member

Menu-bar tests flakiness is unrelated to this PR, I have restarted the build and when it's green I will approve.

@web-padawan web-padawan merged commit bebaf26 into master Sep 2, 2021
@web-padawan web-padawan deleted the feat/menu-bar-item-theme branch September 2, 2021 10:25
tltv added a commit to vaadin/vaadin-context-menu that referenced this pull request Oct 22, 2021
tltv added a commit to vaadin/vaadin-menu-bar that referenced this pull request Oct 22, 2021
tltv added a commit to vaadin/vaadin-context-menu that referenced this pull request Oct 27, 2021
@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with platform 22.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants