Goal:
When you click on the icon menu in the header toolbar, it should be expanded and the content of "<mat-sidenav-content>" should be moved more to the right due to the space of the sidenav menu.
Problem:
When clicking on the icon menu the content of "<mat-sidenav-content>" doesn't move to the right side direction due to the expansion space of the sidenavemenu. The content is static when you expand the sidenav bar menu.
What part am I missing?
Info:
*Using angular 9
*A example of a content that will be moved when you make the sidebar nav menu to appear.
(https://stackblitz.com/angular/qoaqpenxjqy)
*When the menu is not expanded, the icon should appear and not the text.
Stackblitz:
https://stackblitz.com/edit/angular-ymkpvj-hso3tw
Thank you!
<mat-toolbar color="primary" class="example-toolbar">
<button mat-icon-button (click)="isExpanded = !isExpanded" >
<mat-icon>menu</mat-icon>
</button>
<h1 class="example-app-name">Nested Menus</h1>
</mat-toolbar>
<mat-sidenav-container class="example-container" >
<mat-sidenav #sidenav class="example-sidenav"
mode="side"
opened="true"
(mouseenter)="mouseenter()"
(mouseleave)="mouseleave()"
>
<mat-nav-list>
<mat-list-item (click)="showSubmenu = !showSubmenu" class="parent">
<mat-icon mat-list-icon>home</mat-icon>
<span class="full-width" *ngIf="isExpanded || isShowing">Parent Menu</span>
<mat-icon class="menu-button" [ngClass]="{'rotated' : showSubmenu}" *ngIf="isExpanded || isShowing">expand_more</mat-icon>
</mat-list-item>
<div class="submenu" [ngClass]="{'expanded' : showSubmenu}" *ngIf="isShowing || isExpanded">
<a mat-list-item href="...">Submenu Item 1</a>
<a mat-list-item href="...">Submenu Item 2</a>
<mat-list-item (click)="showSubSubMenu = !showSubSubMenu" class="parent">
<span class="full-width" *ngIf="isExpanded || isShowing">Nested Menu</span>
<mat-icon class="menu-button" [ngClass]="{'rotated' : showSubSubMenu}" *ngIf="isExpanded || isShowing">expand_more</mat-icon>
</mat-list-item>
<div class="submenu" [ngClass]="{'expanded' : showSubSubMenu}" *ngIf="isShowing || isExpanded">
<mat-list-item>SubSubmenu Item 1</mat-list-item>
<mat-list-item>SubSubmenu Item 2</mat-list-item>
</div>
</div>
</mat-nav-list>
<mat-nav-list>
</mat-nav-list>
</mat-sidenav>
<mat-sidenav-content>
test test test test test test test
</mat-sidenav-content>
</mat-sidenav-container>
<!-- Copyright 2017 Google Inc. All Rights Reserved.
Use of this source code is governed by an MIT-style license that
can be found in the LICENSE file at http://angular.io/license -->
import {Component, ViewChild} from '#angular/core';
import {FormBuilder, FormGroup} from '#angular/forms';
/** #title Fixed sidenav */
#Component({
selector: 'sidenav-fixed-example',
templateUrl: 'sidenav-fixed-example.html',
styleUrls: ['sidenav-fixed-example.css'],
})
export class SidenavFixedExample {
/**
options: FormGroup;
constructor(fb: FormBuilder) {
this.options = fb.group({
bottom: 0,
fixed: false,
top: 0
});
}
*/
constructor() {}
events: string[] = [];
isExpanded = true;
showSubmenu: boolean = false;
isShowing = false;
showSubSubMenu: boolean = false;
mouseenter() {
if (!this.isExpanded) {
this.isShowing = true;
}
}
mouseleave() {
if (!this.isExpanded) {
this.isShowing = false;
}
}
}
.example-container {
height: 500px;
border: 1px solid rgba(0, 0, 0, 0.5);
}
.example-sidenav-content {
display: flex;
height: 100%;
align-items: center;
justify-content: center;
}
.example-sidenav {
user-select: none;
}
.full-width {
width: 100%;
}
.menu-button {
transition: 300ms ease-in-out;
transform: rotate(0deg);
}
.menu-button.rotated {
transform: rotate(180deg);
}
.submenu {
overflow-y: hidden;
transition: transform 300ms ease;
transform: scaleY(0);
transform-origin: top;
padding-left: 30px;
}
.submenu.expanded {
transform: scaleY(1);
}
Demo make opened propery isExpanded
[opened]="isExpanded"
but if you want to show small icon while closing then you need to change css. Because navigation position is absolute but, content is relative. and content changes with margin-left property to opened property value.
Possible solution
make both position relative and remove margin-left property for content in true condition of opened
.mat-sidenav{
position: relative !important;
height: 100%;
overflow: auto;
float: left;
}
.mat-drawer-content {
margin-left: 0 !important;
}
you should put them inside style.css. Demo
Related
I need to color and zoom the text when the cursor "approaches" the text (so basically when the mouse enters the area of the div surrounding the text). Right now i can make it work coloring the text only when i hover directly on it. I'll paste a snippet of the code.
HTML:
<div fxLayout="row wrap" class="max container">
<div fxFlex="100%" fxLayoutAlign="center">
<!--here there is an image-->
</div>
<div fxFlex="100%" class="centered-text" fxHide fxShow.gt-lg>
<h2 [ngClass]="{'gradient' : this.gradient,'lighter':lighter, 'zoom':zoom, 'scale':1.2}" style="margin: 0;" class="font">
hoverMe
</h2>
</div>
</div>
Typescript:
import {Component, Input, OnInit} from '#angular/core';
#Component({
selector: 'iet-box-academy',
templateUrl: './box-academy.component.html',
styleUrls: ['./box-academy.component.scss']
})
export class BoxAcademyComponent implements OnInit {
#Input() scale = 1;
#Input() img = '';
#Input() title = 'TITOLO';
#Input() descr = '';
#Input() align = "centerer";
#Input() lighter = false;
#Input() zoom = true;
#Input() gradient: boolean = false;
constructor() {
}
ngOnInit(): void {
}
}
CSS:
.container {
position: relative;
text-align: center;
color: black;
}
.zoom {
transition: transform .2s; /* Animation */
margin: 0 auto;
}
.zoom:hover {
transform: scale(1.5);
color: #00D3FF;
}
https://jsfiddle.net/wdfc7g9a/14/
You can add the :hover to the parent and add a child selector:
Change:
.zoom:hover {
transform: scale(1.5);
color: #00D3FF;
}
To:
.container:hover .zoom {
transform: scale(1.5);
color: #00D3FF;
}
Demo:
.container {
border: 1px solid red;
}
.container:hover .zoom {
background: yellow;
}
<div class="container">
This is a text
<div class="zoom">highlight this text</div>
More text
</div>
I recommend you to use centered-text class instead of zoom class. Because it is easier to give a transparent padding to it so you can have the "approaching" animation played without needing to hover directly on the text.
This code will fix your problem the moment you copy paste it to your Custom CSS:
.centered-text {
transition: all 0.3s;
margin: 0 auto;
padding:13px;
}
.centered-text:hover {
transform: scale(1.4);
color: #00D3FF;
transition: all 0.3s;
}
I tried many ways but it's not working. I just need a simple button that is visible only on hover.
I have this:
<div class = "input-edit">
<button type = "button" class = "edit-button">
<mat-icon class = "material-icons"> edit </mat-icon>
</button>
Edit:
SOLUTION:
.input-edit{opacity: 0} .input-edit:hover{opacity: 1 }
CSS is the way to go and as Prakash suggested, that could be one nice approach, use opacity and you can even use a transition to make the effect smooth
.input-edit {
opacity: 0;
transition: opacity 0.5s ease;
}
.input-edit:hover {
opacity: 1;
}
The display: none; property would not work because otherwise the button would not exist. In this case you can give the button an opacity: 0; and for hovering an opacity: 1;.
Here's the code:
.input-edit {
opacity: 0;
transition: all 0.2s; /* Use a transition if you want */
}
.input-edit:hover {
opacity: 1;
}
<div class = "input-edit">
<button type = "button" class = "edit-button">
<mat-icon class = "material-icons"> edit </mat-icon>
</button>
you can use display: none; property
.edit-button{
display: none;
}
.input-edit {
min-height:50px;
}
.input-edit:hover .edit-button{
display: block;
}
<div class = "input-edit">
<button type = "button" class = "edit-button">
<mat-icon class = "material-icons"> edit </mat-icon>
</button>
</div>
.hide {
display: none;
}
.myDIV:hover + .hide {
display: block;
color: red;
}
<div class = "myDIV">Edit</div>
<button type = "button" class = "edit-button hide">
<mat-icon class = "material-icons"> edit </mat-icon>
</button>
I've made a list of categories in the navbar and in these categories. I want to show a dropdown just like a Flipkart website. But when I'm hovering over my categories it shows dropdown but as soon as I move my mouse over the dropdown list my dropdown vanishes.
I'm getting these categories and dropdowns from backend in the form of an array that's why I use ngFor in my Html file to display my categories and dropdown list. Is there any way to expand the hover area over the categories.
My main aim is when I mouse over my dropdown it shows till my mouse is over my dropdown and vanishes after I remove my mouse from the dropdown list.
The categories that I'm getting from backend in the form of an array are
Men
Home&Furniture
Electronics
The dropdown I am getting for these categories-
For Men-Shoes, Watches
For Electronics - Smartwatches, Laptops
home.component.html File
<div class="col-7">
<ul class="row list">
<ng-container *ngFor='let item of menus'>
<li class="px-3 Menu" (mouseover)='overMenu(item.name)'
(mouseout)='leaveMenu(item.name)' >{{item.name}}
<img class="caret ml-1" src="../../../assets/angle-arrow-down.png">
<div class="sub-menu">
<ul class="list2" *ngIf="item.name === 'Men' && flag">
<ng-container *ngFor='let i of arr'>
<li class="text-center">{{i.mensubcat}}</li>
</ng-container>
</ul>
<ul class="list2" *ngIf="item.name === 'Home&Furniture' && flag2">
<ng-container *ngFor='let i of arr'>
<li class="text-center">{{i.mensubcat}}</li>
</ng-container>
</ul>
<ul class="list2" *ngIf="item.name === 'Electronics' && flag2">
<ng-container *ngFor='let i of arr'>
<li class="text-center">{{i.esubcat}}</li>
</ng-container>
</ul>
</div>
</li>
</ng-container>
</ul>
</div>
home.component.css File
.list {
display: flex;
list-style: none;
justify-content: flex-start;
align-items: center;
position: relative;
}
.Menu
{
padding: 9px 20px;
}
.Menu:hover
{
color: rgb(9, 128, 240);
}
.Menu:hover > .caret {
color: rgb(9, 128, 240);
transform: rotate(180deg);
transition: 0.2s;
}
.list2 {
list-style: none;
position: absolute;
line-height: 37px;
display: block;
z-index: 4;
padding: 10px;
background-color: #e1e2e5e3;
border-radius: 5px;
width: 20%;
color:black;
/* padding-left: 0; */
}
home.component.ts File
overMenu(name){
if(name === "Men"){
this.flag = true
}
else if(name === 'Electronics'){
this.flag2 = true
}
}
leaveMenu(name) {
if(name === 'Men'){
this.flag = false
}
else if(name === 'Electronics'){
this.flag2 = false
}
}
I tried with mouseleave instead of mouseout and it did work.
here is the stackblitz i tried
As you can see in the screenshot below, I hava a tab on the bottom of my page. When I click on it, I want it to slide underneath the <div> containing "Test" using angular animations. The problem is, that the pagesize should be responsive and therefore I cannot use px-values. I tried percentage as well, but that value refers to my tab-div, not the overall height.
Screenshot
My component:
#Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.scss'],
animations: [
trigger('tabState', [state('default', style({
transform: 'translateY(0)'
})
),
state('open', style({
transform: 'translateY(-100%)'
})),
transition('default <=> open', animate(500))
])
]})
export class TestComponent {
state = 'default';
onComeIn() {
this.state === 'default' ? this.state = 'open' : this.state = 'default';
}
}
My HTML:
<div class="mainContainer">
<mat-toolbar color="primary">
<div class="d-flex align-items-center justify-content-between">
<span>Test</span>
</div>
</mat-toolbar>
<div class="mainContentContainer">
<div class="d-flex flex-column" style="height: 100%">
<div>content</div>
<div class="mt-auto">
<div class="tabContainer" [#tabState]="state">
<div class="tab" (click)="onComeIn()">Tab</div>
</div>
</div>
</div>
And finally the css:
.tab {
box-sizing: border-box;
height: 4.2em;
width: 33%;
background-color: white;
padding: 1em 1.2em 0.45em 1.2em;
border-radius: 0.5em 0.5em 0 0;
box-shadow: 0 0.05em #b7b7b7;
}
.mainContainer {
width: 100%;
display: flex;
flex-direction: column;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.mainContentContainer {
flex: 1;
background-color: #455864;
}
The issue is more about css :
I changed the initial value of the tabContainer class to this :
.tabContainer {
position: fixed;
bottom: 0;
width: 100%;
}
Then in the animation definition, removed the bottom and added the top one :
state('open', style({
bottom: 'initial',
top: '20px'
})),
Here is the running example in editor.
I'm trying to display a overlay when a certain Input field is clicked. I'm doing this in react. How can I do this?
This is my code
import React, { Component } from 'react';
import cam from '../../Resources/img/cam.png';
import SinglePost from '../../Components/Post/single_post';
class Middle extends Component {
constructor(props) {
super(props);
this.state = {
posts: []
}
}
render() {
function popup_ques(e) {
e.preventDefault();
alert("now the overlay should appear");
}
return (
<div className="middle_div">
<input className='post_data_input' placeholder="Ask your question here" ref="postTxt" onClick={popup_ques}/>
</div>
);
}
}
export default Middle;
What is the approach I should take?
I have created a sample react component.
I hope this will help you in somewhat way to achieve what you want.
class Test extends React.Component {
constructor(props) {
super(props);
this.state = {
style : {
width : 350
}
};
this.openNav = this.openNav.bind(this);
this.closeNav = this.closeNav.bind(this);
}
componentDidMount() {
document.addEventListener("click", this.closeNav);
}
componentWillUnmount() {
document.removeEventListener("click", this.closeNav);
}
openNav() {
const style = { width : 350 };
this.setState({ style });
document.body.style.backgroundColor = "rgba(0,0,0,0.4)";
document.addEventListener("click", this.closeNav);
}
closeNav() {
document.removeEventListener("click", this.closeNav);
const style = { width : 0 };
this.setState({ style });
document.body.style.backgroundColor = "#F3F3F3";
}
render() {
return (
<div>
<h2>Fullscreen Overlay Nav Example</h2>
<p>Click on the element below to open the fullscreen overlay navigation menu.</p>
<p>In this example, the navigation menu will slide in, from left to right:</p>
<span style={{fontSize:30,cursor:"pointer"}} onClick={this.openNav}>☰ open</span>
<div
ref = "snav"
className = "overlay"
style = {this.state.style}
>
<div className = "sidenav-container">
<div className = "text-center">
<h2>Form</h2>
<p>This is a sample input form</p>
</div>
<a
href = "javascript:void(0)"
className = "closebtn"
onClick = {this.closeNav}
>
×
</a>
<div className = "list-group">
{/*your form component goes here */}
{this.props.children}
</div>
</div>
</div>
</div>
);
}
}
ReactDOM.render(
<Test/>,
document.getElementById('test')
);
.overlay {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0, 0.9);
overflow-x: hidden;
transition: 0.5s;
}
.overlay-content {
position: relative;
top: 25%;
width: 100%;
text-align: center;
margin-top: 30px;
}
.overlay a {
padding: 8px;
text-decoration: none;
font-size: 36px;
color: #818181;
display: block;
transition: 0.3s;
}
.overlay a:hover, .overlay a:focus {
color: #f1f1f1;
}
.overlay .closebtn {
position: absolute;
top: 20px;
right: 45px;
font-size: 60px;
}
#media screen and (max-height: 450px) {
.overlay a {font-size: 20px}
.overlay .closebtn {
font-size: 40px;
top: 15px;
right: 35px;
}
}
.overlay h2, .overlay p {
color:white;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>
<div id="test"></div>
Input:
<input onFocus={() => this.setState({show_overlay: true})} />
somewhere arround in same render() function add overlay div:
<div
style={{display: this.state.show_overlay === true ? 'block' : 'none'}}
>
overlay
</div>
of course add styling to div as needed to have proper overlay effect, what's needed by your UI
To turn overlay off, you will need to add another event listener on some action, like e.g. click
<button onClick={() => this.setState({show_overlay: false})}>
Close overlay
</button>