Skip to content

Commit 68bb44c

Browse files
devversionjelbourn
authored andcommitted
fix(slide-toggle): truncate label content with ellipsis (#9166)
* Instead of showing the text overflow of slide-toggle content, an ellipsis for too long labels will be shown. Fixes #5212
1 parent e62afdf commit 68bb44c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/lib/slide-toggle/slide-toggle.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@import '../core/ripple/ripple';
33
@import '../core/style/elevation';
44
@import '../core/style/vendor-prefixes';
5+
@import '../core/style/list-common';
56
@import '../../cdk/a11y/a11y';
67

78
$mat-slide-toggle-thumb-size: 20px !default;
@@ -17,6 +18,7 @@ $mat-slide-toggle-bar-track-width: $mat-slide-toggle-bar-width - $mat-slide-togg
1718
.mat-slide-toggle {
1819
display: inline-block;
1920
height: $mat-slide-toggle-height;
21+
max-width: 100%;
2022

2123
line-height: $mat-slide-toggle-height;
2224

@@ -53,6 +55,10 @@ $mat-slide-toggle-bar-track-width: $mat-slide-toggle-bar-width - $mat-slide-togg
5355
cursor: pointer;
5456
}
5557

58+
.mat-slide-toggle-content {
59+
@include mat-truncate-line();
60+
}
61+
5662
/* If the label should be placed before the thumb then we just change the orders. */
5763
.mat-slide-toggle-label-before {
5864
.mat-slide-toggle-label { order: 1; }
@@ -131,6 +137,10 @@ $mat-slide-toggle-bar-track-width: $mat-slide-toggle-bar-width - $mat-slide-togg
131137
width: $mat-slide-toggle-bar-width;
132138
height: $mat-slide-toggle-bar-height;
133139

140+
// Prevent shrinking of the bar container. It can happen that the content is long enough to
141+
// shrink the bar and the thumb.
142+
flex-shrink: 0;
143+
134144
border-radius: $mat-slide-toggle-bar-border-radius;
135145

136146
@include cdk-high-contrast {

0 commit comments

Comments
 (0)