Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make Angular Material Mat-Button-Toggle-Group responsive

I have a mat-button-toggle-group with 6 button-toggles. On Desktop all Buttons should be in one line. On smaller screens the group should break and display 2 lines of buttons like this: enter image description here

This is my code so far (i'm using flexbox-grid):

<mat-button-toggle-group class="col-xs-12">
      <mat-button-toggle class="col-xs-4 col-lg-2" value="1">1 Monat</mat-button-toggle>
      <mat-button-toggle class="col-xs-4 col-lg-2" value="3">3 Monate</mat-button-toggle>
      <mat-button-toggle class="col-xs-4 col-lg-2" value="6">6 Monate</mat-button-toggle>
      <mat-button-toggle class="col-xs-4 col-lg-2" value="12">1 Jahr</mat-button-toggle>
      <mat-button-toggle class="col-xs-4 col-lg-2" value="60">5 Jahre</mat-button-toggle>
      <mat-button-toggle class="col-xs-4 col-lg-2" value="120">10 Jahre</mat-button-toggle>
  </mat-button-toggle-group>

If works fine on desktop, but on mobile screen size, there are only 3 Buttons visible (the three that should be in the second line are not visible): enter image description here

How can I get my mat-button-toggle-group to break into two lines?

like image 918
maidi Avatar asked Jan 23 '19 17:01

maidi


People also ask

How to create mat button toggle group in Angular Material?

First, install the angular material using the above-mentioned command. After completing the installation, Import ‘MatButtonToggleModule,’ from ‘@angular/material’ in the app.module.ts file. Then use <mat-button-toggle-group> and </mat-button-toggle> tags to create angular button toggle group.

How to create toggle buttons in angular?

To build toggle buttons in angular, we will use the profound angular material library. You will be given code examples of various types of toggle buttons using the mat-button-toggle-group attribute. Ideally, the mat-button-toggle property is used to invoke on/off toggles with resemblance to a normal button.

What are <mat-button- toggle> toggles?

<mat-button-toggle> are on/off toggles with the appearance of a button. These toggles can be configured to behave as either radio-buttons or checkboxes. While they can be standalone, they are typically part of a mat-button-toggle-group. By default, mat-button-toggle-group acts like a radio-button group- only one item can be selected.

How to create a responsive navigation bar in angular?

Here is my favorite way of creating a responsive Navigation Bar in Angular. If you use Angular 6, make sure you use a version 6.1+ 1) Install necessary packages. Type in your terminal: npm install --save @angular/material @angular/cdk @angular/animations npm install @angular/flex-layout --save


1 Answers

You have to set the flex-wrap property to wrap for the toggle-group element:

mat-button-toggle-group {
  flex-wrap: wrap;
}

Then just fix up the borders as you please.

like image 159
night_owl Avatar answered Sep 28 '22 00:09

night_owl