I got this stackblitz example for lists with selection as shown in below image.
In the selection list,the list is selecting fine but how can i remove the checkbox?
I got this stackblitz example for lists with selection as shown in below image.
In the selection list,the list is selecting fine but how can i remove the checkbox?
add display:none
for this
I have create a demo on Stackblitz
.css /.sccc
:host {
::ng-deep.mat-pseudo-checkbox{
display: none !important;
}
}
Ng-deep is deprecated. Alternatively use: encapsulation: ViewEncapsulation.None
TS
@Component({
selector: 'component-name',
...
encapsulation: ViewEncapsulation.None
})
CSS
component-name .mat-pseudo-checkbox {
display: none !important;
}
Add attribute [multiple]="false"
in <mat-selection-list>
tag. Works for me!
Source example: https://material.angular.io/components/list/examples#list-single-selection
Use hideSingleSelectionIndicator in mat-selection-list like this: <mat-selection-list [multiple]="false" hideSingleSelectionIndicator>
"By default, MatSelectionList displays radio or checkmark indicators to identify selected items. While you can hide the radio indicator for single-selection via hideSingleSelectionIndicator, this makes the component less accessible by making it harder or impossible for users to visually identify selected items."
See https://material.angular.io/components/list/overview#selection
An interesting alternative would be to use button toggle group with vertical orientation.
Better than these options, there is a built in option called hideSingleSelectionIndicator. You can couple this with some css as well to default highlight. https://material.angular.io/components/list/overview#selection
//this sets the background color of the selected item in the list
#my-list-id[aria-selected="true"] {
background: rgb(232,228,228);
}
<mat-selection-list hideSingleSelectionIndicator [multiple]="false">
<mat-list-option id="my-list-id"> 1 </mat-list-option>
<mat-list-option> 2 </mat-list-option>
</mat-selection-list>
If you remove the multiple
directive from <mat-select></mat-select>
the checkboxes should not be displayed.
If you want to do it using CSS then you need to add a panelClass
, this will allow you to specify the options that you want to modify.
<mat-select multiple panelClass="test-class">
...
</mat-select>
::ng-deep .test-class .mat-pseudo-checkbox {
display: none !important;
}
to avoid using ::ng-deep
you can place the CSS rules in the styles.css file at the root