Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mat-radio-button and mat-checkbox don't line wrap #10954

Open
battre opened this issue Apr 23, 2018 · 9 comments
Open

mat-radio-button and mat-checkbox don't line wrap #10954

battre opened this issue Apr 23, 2018 · 9 comments
Labels
area: material/checkbox area: material/radio G This is is related to a Google internal issue P4 A relatively minor issue that is not relevant to core functions

Comments

@battre
Copy link

battre commented Apr 23, 2018

Bug, feature request, or proposal:

Proposal: change <mat-radio-button> or <mat-checkbox> to line-wrap its contents by default or add an option.

What is the expected behavior?

I can put a text into a <mat-radio-button> or <mat-checkbox> that is longer than what fits into the viewport.

What is the current behavior?

The content in a or does not line wrap. If you have a lot of text in a it gets cut at the end.

A workaround would be
<mat-radio-button><span style="white-space: normal;">{{mylongtext}}</span></mat-radio-button>

What are the steps to reproduce?

https://stackblitz.com/edit/angular-material2-issue-uaeetd?file=app/app.component.html

What is the use-case or motivation for changing an existing behavior?

I have a pretty narrow window and need to put checkboxes and radio buttons in there.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

I think all of them.

Is there anything else we should know?

@hcbpassos
Copy link

hcbpassos commented Jun 24, 2018

@battre I think yout workaround is not very clear. For those who didn't understand in a first moment, like me, what you got to do is let your tag without any content and put your text outside it. E.g.:

<mat-radio-group>
  <div *ngFor="let item of items">
    <mat-radio-button [value]="item.id"></mat-radio-button>
    <!-- your content goes right below -->
    <span>{{ item.description }}</span>
  </div>
</mat-radio-group>

This should solve your problem.

@davidmorissette
Copy link

Redefine that style:

.mat-radio-label {
   white-space: normal;
}

@josephperrott josephperrott added P4 A relatively minor issue that is not relevant to core functions G This is is related to a Google internal issue labels Sep 5, 2018
@jek-bao-choo
Copy link

jek-bao-choo commented Mar 5, 2019

Redefine that style:

.mat-radio-label {
   white-space: normal;
}

white-space: normal didn't work. Not sure why. The <span></span> technique worked.

@sergioebc
Copy link

=== styles.css ===

.mat-checkbox-layout {
white-space: normal !important;
}

.mat-radio-label {
white-space: normal !important;
}

@artesgo
Copy link

artesgo commented Jun 17, 2019

make sure to have your overrides in styles.scss
having it in spans isn't accessible

@PowerKiKi
Copy link
Contributor

This is a (partial) duplicate of #8416

@bernardogontijo
Copy link

@battre I think yout workaround is not very clear. For those who didn't understand in a first moment, like me, what you got to do is let your tag without any content and put your text outside it. E.g.:

<mat-radio-group>
  <div *ngFor="let item of items">
    <mat-radio-button [value]="item.id"></mat-radio-button>
    <!-- your content goes right below -->
    <span>{{ item.description }}</span>
  </div>
</mat-radio-group>

This should solve your problem.

doing this, the text will lose the click event that check the radio button.

@battre
Copy link
Author

battre commented Jan 19, 2021

Looks like the rendering of my comment has changed. I have escaped all HTML tags with backticks and it should be readable now.

@thiagoteberga
Copy link

I solved the problem adding ::ng-deep.

::ng-deep.mat-radio-label {
  white-space: normal !important;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: material/checkbox area: material/radio G This is is related to a Google internal issue P4 A relatively minor issue that is not relevant to core functions
Projects
None yet
Development

No branches or pull requests