Angular material mat menu styling issue - angular-material

I have two components that using mat menu. I just want to add some extra styling for one mat menu in one component. I have used this css inside the component css
::ng-deep.mat-menu-panel
{
position: fixed !important;
right : 2%;
}
Now the issue is the css is applying to the other component mat menu also.
How can i resolve this?

Add your panel styling to your global style sheet:
.fixed-menu-panel
{
position: fixed !important;
right : 2%;
}
Add the panel style to the mat-menu:
<mat-menu class="fixed-menu-panel">
StackBlitz: https://stackblitz.com/edit/angular-9bheaf?file=index.html

The challenge is that the menu is rendered in an overlay container attached to the parent document and not the button itself... with this in mind, you will need to think about how to grab a reference to that mat-menu-panel and append a class to it to make it unique on menu open.
For example, you could do something like the following to accomplish this.
Create a component method that will receive the templateRef as an argument. It will get the mat-menu-panel using Renderer2 and append a class to it of styled
styleMenu(el) {
const menuPanel = this.ren.parentNode(this.ren.parentNode(el.items.first['_elementRef'].nativeElement));
this.ren.addClass(menuPanel, 'styled')
}
Then in your view, use the (menuOpened) event emitter to call the styleMenu method when the menu opens, and pass the #styledMenu templateRef as an argument.
<button mat-button [matMenuTriggerFor]="styledMenu" (menuOpened)="styleMenu(styledMenu)">styled</button>
<mat-menu #styledMenu="matMenu">
Then your CSS will look like this
::ng-deep .mat-menu-panel.styled
{
position: fixed !important;
right : 2%;
}
This is one approach, you could also roll all of this into a directive and then just apply the directive selector where you need it.
Stackblitz
https://stackblitz.com/edit/angular-5nixtl?embed=1&file=app/menu-overview-example.ts

Related

How to center align the text in Vaadin TextField

I read the CSS styling section (https://vaadin.com/docs/v14/flow/styling/styling-components) and it mentions that global CSS doesnt affect the 'INPUT" field in the shadow DOM, So styling has to be added to shdaow DOM, But unfortunately no where does it explicitly say HOW to add the styling to the shadow DOM. Note. im using mainly Flow pure java with a bit of CSS.
I tried retrieving the elementt from component then retrieving the shadowRoot, then from root, retrieve the 'input' element to add styling to it, unfortunately that didnt work, shadowroot was null (this code executed from the onAttach() method in the view class)
private void setTextAlignCenterForTextFields(TextField textField) {
//find the internal 'Input' and set the styling to text-align=center, unfortunately
// you cant do that with global css, since the 'input' element is in shadow root
textField.getElement()
.getShadowRoot()
.get()
.getChildren()
.filter( elem -> "INPUT".equalsIgnoreCase(elem.getTag()))
.forEach(inputElem -> inputElem.getStyle().set("text-align", "center"));
}
Any ideas would be appreciated. I'm using Vaadin version 14.5.1.
There's already a theme variant to align the text
centerTextField.addThemeVariants(TextFieldVariant.LUMO_ALIGN_CENTER);
see https://vaadin.com/components/vaadin-text-field/java-examples/theme-variants
As for how to attach CSS to shadow root, basically use themeFor, see https://vaadin.com/docs/v14/flow/styling/importing-style-sheets/#component-styles
You can use CSS to target the value part:
.textfieldClass::part(value) {
text-align: center;
}
This video explains styling CSS parts: https://youtu.be/Y0uxb4ga44Y

Angular Material: Change Background color of tabs when clicked/active

I want to remove the background-color effect applying when clicked on tab in angular material:
Here is the link of md-tabs
When I click on the tab, I can see a background-color is applying to the div element:
Here is the screenshot
I tried to over-ride the style with the following code, but not taking into effect:
.md-ripple-container:active{
background-color: none; !important
}
Help!!
Just use the .md-tab.md-active class in css. see the below example.
http://codepen.io/next1/pen/JXbVQN
You can override material styling from your scss/css. Like this:
/deep/ .mat-tab-group.mat-primary mat-tab-label-active{
background-color: red;
}
Due to view encapsulation, you need to use /deep/ selector that will allow you to get hold of the Material class added when the component is rendered.

Contao: Teasers in dropdown navigation

I need to make a dropdown navigation, where for every parent navigation item, in the dropdown area I show the child pages + 3 images with a title linked to other pages.
I would need something like the 'Custom Navigation' module with an option to select images (or add a custom class, and get the image from the page).
Is there an extension which I could use for this? If not, would be easier/faster to change/extend a core module, or should I create a new one?
Thanks!
EXAMPLE ('Kollektion' menu-item hovered. The gray area is the submenu container)
I don't know of an extension that would allow including an image to a specific link in a navigation menu. But if you are willing to do it with CSS styles, here's how I would do it:
Any page can have multiple custom CSS classes and they do apply to the navigation (unless the navigation template has been changed in such a way that they don't anymore). The place where you enter these CSS classes is at the bottom of the Edit page view, under expert settings. Add any CSS classes you want and then edit the style sheet to make them look right.
If the three pages are not supposed to be subpages for the current page, but lead somewhere else, you can use the "Internal redirect" page type for them.
The CSS could be something like this in addition to your regular styling:
.level_2 li {
float: left;
clear: left; /* this is to stack them on top of one another*/
}
.level_2 li.special_class {
display: inline-block;
vertical-align: top;
}
.level_2 li.special_class:before {
display: block;
content: '';
width: /* the intended image width */
height: /* the intended image height */
}
.level_2 li.special_class.foo {
background-image: url('foo');
}
.level_2 li.special_class.bar {
background-image: url('bar');
}
...
Please remember that this isn't supposed to be a complete solution, but rather a principle upon which you can build your own. You may want to add backwards compatibility to older browsers (or not), etc.
I think there is an extension to allow you do that. check this link Navigation with images
and may be this one also Navigations-Bild
Either of this should give you what you want but with a little styling

Vaadin OptionGroup caption location

I am trying to get an OptionGroup to have the labels next to them, on the right hand side like normal radio buttons in every other UI I have ever used, instead of underneath them. I do not see anything in the API regarding how to change the layout of this? Anyone point me in the correct direction?
Follow these steps:
Add these lines to your css
.v-select-optiongroup-horizontal .v-select-option {
display: inline-block;
}
.v-select-optiongroup-horizontal {
white-space: nowrap;
}
.v-select-optiongroup-horizontal
.v-select-option.v-radiobutton {
padding-right: 10px;
}
And call
group.setStyleName("horizontal");
where group is the OptionGroup object.
Is it possible that you inherited some styles that display the text like that?
Did you try to call hzl.setSizeUndefined()? Or maybe playing with the width (setWidth()).

Can I set a Custom Icon for a jQueryUI Button

Is it possible to create a jQueryUI Button with a custom icon, ie: an icon that is not part of the sprite icons that are provided with jQueryUI???
I am using the ButtonSet functionality for a group of 3 checkboxes but need a more stylised icon than what is provided out of the box...
Worked it out with a CSS hack.
Setup the button as per normal and give the primary icon the "Error" class defined below
.Error
{
background-image: url('Images/Icons/16/Error.png') !important;
}
The !important overrides the ui-icon definition for background-image.
I took this approach for one of my buttons and I discovered some interesting things:
I didn't need to use the "!important" override
I needed to set background-position for my button (otherwise I think the background was being displayed well outside the button)
It looks like you can also put anything you like in the jQueryUI primary icon name - it just needs something as a placeholder.
For my uses I ended up with:
Javascript:
jQuery(function() {
jQuery('#share-button').button({
icons: { primary: "icons/share" }
});
});
CSS:
#share-button > span.ui-icon {
background-image: url(icons/share.png);
background-position:0px 3px;}
HTML:
<button id='share-button'>Share</button>

Resources