I have ng-select wrapped inside mat-expansion-panel. I would like to be able to increase the height of the dropdown list to go beyond the height of mat-expansion-panel but I cannot get that effect. I have tried to play around with z-index but still not working.
Stackblitz Example here for list of countries
My code:
HTML
<mat-accordion>
<mat-expansion-panel class="shadow">
<mat-expansion-panel-header>
<mat-panel-title>
<b>Location</b>
</mat-panel-title>
</mat-expansion-panel-header>
<div class="location">
Country
<ng-select class="m-t-10" [(ngModel)]="selectedCountry">
<ng-option *ngFor="let country of countries" value="country.value">
<div class="famfamfam-flags {{country?.value.toLowerCase()}}"></div>
{{country?.label}}
</ng-option>
</ng-select>
</div>
<mat-divider></mat-divider>
<div class="location">
Province
<ng-select class="m-t-10" [(ngModel)]="selectedProvince">
<ng-option *ngFor="let province of provinces" value="country.value">
{{province?.label}}
</ng-option>
</ng-select>
</div>
<mat-divider></mat-divider>
<div class="location">
District
<ng-select class="m-t-10" [(ngModel)]="selectedDistrict">
<ng-option *ngFor="let district of districts" value="district.value">
{{district?.label}}
</ng-option>
</ng-select>
</div>
</mat-expansion-panel>
</mat-accordion>
import { Component,ViewEncapsulation} from "#angular/core";
import { CountryListService } from "./../country.service";
#Component({
selector: "app-location",
templateUrl: "./location.component.html",
styleUrls: ["./location.component.css"],
encapsulation: ViewEncapsulation.None,
providers: [CountryListService]
})
export class LocationComponent {
constructor(private countryList: CountryListService) {}
selectedCountry = "Select";
selectedProvince = "Select";
selectedDistrict = "Select";
countries = this.countryList.getCountries();
provinces = [{ label: "province1", value: "province1" }];
districts = [{ label: "Dist1", value: "District1" }];
}
Countries Service
import {Injectable} from '#angular/core';
#Injectable()
export class CountryListService{
constructor(){}
getCountries(){
return CountryListService.COUNTRIES;
}
private static readonly COUNTRIES = [
{value: 'AF', label: 'Afghanistan'},
{value: 'AX', label: 'Ă…land Islands'},
{value: 'AL', label: 'Albania'},
{value: 'DZ', label: 'Algeria'},
{value: 'AS', label: 'American Samoa'},
{value: 'AD', label: 'Andorra'},
{value: 'AO', label: 'Angola'},
{value: 'AI', label: 'Anguilla'},
{value: 'AQ', label: 'Antarctica'},
{value: 'AG', label: 'Antigua and Barbuda'},
{value: 'AR', label: 'Argentina'}
];
}
I'm not sure about what your are trying to do but I think what you are looking for is :
.ng-dropdown-panel {
position: relative !important;
}
To expand the height of the mat-expansion-panel when you display the dropdown list options.
Related
I would like to show the preview of the selected image busing Angular, as of now if we click all images are selected, can any one suggest me how to show preview of the selected one and if we select another image previously selected image should be unselect and display new image.
public images: Array<object> = [
{
src: 'https://picsum.photos/250/250/?image=110',
description: 'Notte in hotel di lusso',
price: 250
},
{
src: 'https://picsum.photos/250/250/?image=58',
description: 'Escursione alla scoperta degli animali dell\'isola',
price: 160
}
];
HTML:
<div class="image__container" [ngClass]="{ 'selected': selected }">
<img class="image" [src]="item.src">
<div
class="image__description"
(click)="selected = !selected"
>
<div class="image__description--content">
<div class="image__description--price">
{{ item.price }}
</div>
</div>
</div>
Stackblitz
Thanks for the detailed question, You can check the below stackblitz, I needed to just add a parent property that tracks the currently selected row, then emit an event from the child which updates the latest value from the child. Then if the changes do not show up, we can call this.cdr.detectChanges() to trigger change detection manually. Please check the below code and let me know if any questions.
import {
Component,
ChangeDetectionStrategy,
ChangeDetectorRef,
ViewChildren,
QueryList,
} from '#angular/core';
import { GridItemComponent } from '../grid-item/grid-item.component';
#Component({
selector: 'aer-grid',
templateUrl: './grid.component.html',
styleUrls: ['./grid.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class GridComponent {
currentlySelected;
#ViewChildren('gridItem') gridItems: QueryList<GridItemComponent>;
public images: Array<object> = [
{
src: 'https://picsum.photos/250/250/?image=110',
description: 'Notte in hotel di lusso',
price: 250,
},
{
src: 'https://picsum.photos/250/250/?image=58',
description: "Escursione alla scoperta degli animali dell'isola",
price: 160,
},
{
src: 'https://picsum.photos/250/250/?image=76',
description: 'Gita in bicicletta',
price: 50,
},
{
src: 'https://picsum.photos/250/250/?image=61',
description: "Visita di una delle cittadine dell'isola",
price: 25,
},
{
src: 'https://picsum.photos/250/250/?image=64',
description: 'Gita in motoscafo',
price: 85,
},
{
src: 'https://picsum.photos/250/250/?image=71',
description: 'Biglietto aereo',
price: 500,
},
{
src: 'https://picsum.photos/250/250/?image=65',
description: 'Cocktail sulla spiaggia',
price: 5,
},
];
constructor(private cdr: ChangeDetectorRef) {}
updateCurrentlySelected(value: number) {
this.currentlySelected = value;
this.cdr.markForCheck();
// not needed below line
// this.gridItems.forEach((item) => item.detectChanges());
}
}
html
<section class="grid-container">
<ng-container *ngFor="let image of images; let index = index">
<aer-grid-item
#gridItem
[item]="image"
[index]="index"
[currentlySelected]="currentlySelected"
(emitChange)="updateCurrentlySelected($event)"
></aer-grid-item>
</ng-container>
</section>
<!-- Preview of the selected image-->
<br />
<br />
<section>
*ngIf="images && images[currentlySelected] && images[currentlySelected].src"
Preview:
<img [src]="images[currentlySelected].src" />
stackblitz
I am using Angular Material library multiselect. I added an element to this selection, when clicking on which all the elements of the list will be selected, but the problem is that in this case all these elements, together with All, fall into the select field and it looks like this "Value 1, Value 2, Value 3 , Value 4, All ". How can I make it so that in this field when selecting all elements, only the value "All" remains without the rest of the selected elements?
export class AppComponent {
searchUserForm: FormGroup;
userTypeFilters = [
{
key: 1, value: 'Value 1',
},
{
key: 2, value: 'Value 2',
},
{
key: 3, value: 'Value 3',
},
{
key: 4, value: 'Value 4',
}
];
#ViewChild('allSelected') private allSelected: MatOption;
constructor(private fb: FormBuilder){}
ngOnInit() {
this.searchUserForm = this.fb.group({
userType: new FormControl('')
});
}
toggleAllSelection() {
if (this.allSelected.selected) {
this.searchUserForm.controls.userType
.patchValue([...this.userTypeFilters.map(item => item.key), 0]);
} else {
this.searchUserForm.controls.userType.patchValue([]);
}
}
}
<form [formGroup]="searchUserForm" fxFlex fxLayout="column" autocomplete="off" style="margin: 30px">
<mat-select placeholder="User Type" formControlName="userType" multiple>
<mat-option *ngFor="let filters of userTypeFilters" [value]="filters.key">
{{filters.value}}
</mat-option>
<mat-option #allSelected (click)="toggleAllSelection()" [value]="0">All</mat-option>
</mat-select>
</form>
Demo is here
Here is the solution
<form [formGroup]="searchUserForm" fxFlex fxLayout="column" autocomplete="off" style="margin: 30px">
<mat-select placeholder="User Type" formControlName="userType" multiple>
<mat-select-trigger *ngIf="allSelected.selected">
<span>
ALL
</span>
</mat-select-trigger>
<mat-option *ngFor="let filters of userTypeFilters" [value]="filters.key">
{{filters.value}}
</mat-option>
<mat-option #allSelected (click)="toggleAllSelection()" [value]="0">All</mat-option>
</mat-select>
</form>
Hello is there a way to set a custom width in my react select button?
I would like it if I can use bootstrap to do that so it can be responsive but if not its okay.
Here is my code:
import Select, { components } from 'react-select';
export default class AccomodationType extends Component {
render() {
const options = [
{ value: 'chocolate', label: 'Chocolate' },
{ value: 'strawberry', label: 'Strawberry' },
{ value: 'vanilla', label: 'Vanilla' }
]
return(
<div>
<Select
options= {options}
isClearable
isSearchable
name="color"
/>
</div>
)
}
}
I just used bootstrap sizing for it!
Here is what I added:
<Select
className="w-25 p-3"
options= {options}
isClearable
isSearchable
name="color"
/>
I tried using the Ant Design TreeSelect component withing a Modal, but when opening that TreeSelect the values of the tree is hidden behind the Modal.
I tried using a higher value of z-index but it didn't help! Any ideas?
import React from "react";
import ReactDOM from "react-dom";
import { version } from "antd";
import { TreeSelect } from "antd";
import {
Button,
ComposedModal,
ModalBody,
ModalFooter,
ModalHeader
} from "carbon-components-react";
import "antd/dist/antd.css";
import "./index.css";
const treeData = [
{
title: "Node1",
value: "0-0",
key: "0-0",
children: [
{
title: "Child Node1",
value: "0-0-1",
key: "0-0-1"
},
{
title: "Child Node2",
value: "0-0-2",
key: "0-0-2"
}
]
},
{
title: "Node2",
value: "0-1",
key: "0-1"
}
];
function treeSelectChange(e, value) {
console.log(e);
//e.preventDefault()
}
ReactDOM.render(
<div className="App">
<h1>antd version: {version}</h1>
{/* <p>
Please <b>fork</b> this sandbox to reproduce your issue.
</p> */}
<ComposedModal
open={true}
// onClose={(e) => this.closeRuleEditorModal(e) }
className=""
>
<ModalHeader title="Rule Editor" className="HeaderToolbar White" />
<ModalBody>
<TreeSelect
// className="on-front"
style={{
width: "100%"
}}
// value={element.Value}
dropdownStyle={{
maxHeight: 400,
overflow: "auto",
zIndex: 10000
// position: "absolute"
}}
treeData={treeData}
// placeholder={element.Name}
treeDefaultExpandAll
onChange={treeSelectChange}
/>
</ModalBody>
<ModalFooter>
<Button
kind="secondary"
size="small"
// onClick={(e) => this.closeRuleEditorModal(e) }
>
Cancel
</Button>
<Button
kind="primary"
id="btnSave"
size="small"
// onClick={() => this.fabricateCustomizedProject()}
>
Save
</Button>
</ModalFooter>
</ComposedModal>
</div>,
document.getElementById("root")
);
To reproduce issue, you may also use
https://codesandbox.io/s/antd-reproduction-template-ci559
Update
It worked for me when I used a z-index with value 10000 (have no idea why I had to set so high value, seems one of the css that I used for other components -Modal- is using a big z-index inside).
dropdownStyle={{ maxHeight: 400, overflow: 'auto',zIndex:"100000" }}
It works for me
I'm trying to build a vue.js front-end and the design is calling for 100% width tiles with a dynamic background image that will be passed along the rest of the content to the page. I already have the payload passing to the component that renders each tile, but I need to render the background image for each of the tiles. I also need to mention that the images are actually 3 images for each tile that need to render for each of our 3 breakpoints. So far I was able to pass one image by using :style="'background-image: url(' + backgroundImage + ')'" but this only serves one image per tile. My question is, what would be the best way to pass all 3 images per tile and render them correctly?
I have heard online that I should just use srcset and pass all 3 to an <img> tag, and make that image the background by using CSS, but that just seems unorthodox.
Is there a more elegant way to deal with responsive background images in reusable components in vue.js?
Home Page
<template>
<div class="Home">
<HomePageTile v-for="tile in tiles" :key="tile.title" :tile-title="tile.title" :tile-desc="tile.description" :tile-type="tile.position" :background-image="tile.backgroundImage"/>
</div>
</template>
<script>
import HomePageTile from '#/components/HomePageTile'
import tileImage1 from '#/assets/optimized/image1.jpg'
import tileImage2 from '#/assets/optimized/image2.jpg'
import tileImage3 from '#/assets/optimized/image3.jpg'
import tileImage4 from '#/assets/optimized/image4.jpg'
export default {
name: 'Home',
components: {
HomePageTile: HomePageTile
},
data () {
return {
tiles: [
{
title: 'Title 1',
description: 'Content 1',
position: 'right',
backgroundImage: tileImage1
}, {
title: 'Title 2',
description: 'Content 2',
position: 'right',
backgroundImage: tileImage2
}, {
title: 'Title 3',
description: 'Content 3',
position: 'right',
backgroundImage: tileImage3
}, {
title: 'Title 4',
description: 'Content 4',
position: 'right',
backgroundImage: tileImage4
}
]
}
}
}
</script>
Tile Component
<template>
<div :class="tilePosition(tileType)" :style="'background-image: url(' + backgroundImage + ')'">
<template v-if="tileType">
<div class="home-page-tile--container home-page-tile--container__with-desc">
<h2 class="home-page-tile--container--title">{{ tileTitle }}</h2>
<p class="home-page-tile--container--description">{{ tileDesc }}</p>
</div>
<div class="home-page-tile--call-to-action" v-if="callToAction">
<p class="home-page-tile--call-to-action--text">{{ callToAction.text }}</p>
<Button class="home-page-tile--call-to-action--button" :button-route="callToAction.buttonPath" :button-text="callToAction.buttonText" :button-style="callToAction.buttonStyle" />
</div>
</template>
<template v-else>
<div class="home-page-tile--container">
<h2 class="home-page-tile--container--title">{{ tileTitle }}</h2>
<Button :button-route="buttonPath" :button-text="buttonText" button-style="pill"/>
</div>
</template>
</div>
</template>
<script>
import Button from './Button'
export default {
name: 'HomePageTile',
props: {
tileType: String,
tileTitle: String,
tileDesc: String,
backgroundImage: String,
buttonText: String,
buttonPath: String,
callToAction: Object
},
components: {
Button: Button
},
data () {
return {
tilePosition: function (el) {
if (el) {
return 'home-page-tile home-page-tile__' + el
} else {
return 'home-page-tile'
}
}
}
}
}
</script>