Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit c7c5da2

Browse files
allan-chencopybara-github
authored andcommitted
fix(linear-progress): fix RTL rendering
Reverse mode is slated to be removed. In the future, set `dir="rtl"` on root instead. PiperOrigin-RevId: 351699027
1 parent fe13dd1 commit c7c5da2

File tree

3 files changed

+64
-38
lines changed

3 files changed

+64
-38
lines changed

packages/mdc-linear-progress/README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ The provided modifiers are:
8585
| Class | Description |
8686
| --------------------- | ------------------------------------------------------- |
8787
| `mdc-linear-progress--indeterminate` | Puts the linear progress indicator in an indeterminate state. |
88-
| `mdc-linear-progress--reversed` | Reverses the direction of the linear progress indicator. |
8988
| `mdc-linear-progress--closed` | Hides the linear progress indicator. |
9089

9190
### Sass Mixins
@@ -124,7 +123,6 @@ MDC Linear Progress Foundation exposes the following methods:
124123
| `setDeterminate(value: boolean) => void` | Toggles the component between the determinate and indeterminate state. |
125124
| `setProgress(value: number) => void` | Sets the progress bar to this value. Value should be between [0, 1]. |
126125
| `setBuffer(value: number) => void` | Sets the buffer bar to this value. Value should be between [0, 1]. |
127-
| `setReverse(value: boolean) => void` | Reverses the direction of the linear progress indicator. |
128126
| `open() => void` | Puts the component in the open state. |
129127
| `close() => void` | Puts the component in the closed state. |
130128

@@ -137,6 +135,5 @@ MDC Linear Progress exposes the following methods:
137135
| `set determinate(value: boolean) => void` | Toggles the component between the determinate and indeterminate state. |
138136
| `set progress(value: number) => void` | Sets the progress bar to this value. Value should be between [0, 1]. |
139137
| `set buffer(value: number) => void` | Sets the buffer bar to this value. Value should be between [0, 1]. |
140-
| `set reverse(value: boolean) => void` | Reverses the direction of the linear progress indicator. |
141138
| `open() => void` | Puts the component in the open state. |
142139
| `close() => void` | Puts the component in the closed state. |

packages/mdc-linear-progress/_mixins.scss

Lines changed: 63 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@
1818
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1919
// THE SOFTWARE.
2020

21+
// stylelint-disable no-unknown-animations --
22+
// Animations keyframes are included in `keyframes.scss`.
23+
// stylelint-disable selector-class-pattern --
24+
// Selector '.mdc-*' should only be used in this project.
25+
2126
@use 'sass:string';
2227
@use '@material/animation/functions' as animation-functions;
2328
@use '@material/feature-targeting/feature-targeting';
29+
@use '@material/rtl/rtl';
2430
@use '@material/theme/theme';
2531
@use '@material/theme/theme-color';
2632
@use './variables';
@@ -133,6 +139,10 @@
133139
@include indeterminate_($query: $query);
134140
@include reversed_($query: $query);
135141

142+
@include rtl.rtl() {
143+
@include _rtl-styles($query: $query);
144+
}
145+
136146
&--closed {
137147
@include feature-targeting.targets($feat-structure) {
138148
opacity: 0;
@@ -161,22 +171,6 @@
161171
@include bar-color(primary, $query: $query);
162172
@include buffer-color(variables.$baseline-buffer-color, $query: $query);
163173
}
164-
165-
.mdc-linear-progress--indeterminate.mdc-linear-progress--reversed {
166-
.mdc-linear-progress__primary-bar {
167-
@include feature-targeting.targets($feat-structure) {
168-
right: -145.166611%;
169-
left: auto;
170-
}
171-
}
172-
173-
.mdc-linear-progress__secondary-bar {
174-
@include feature-targeting.targets($feat-structure) {
175-
right: -54.888891%;
176-
left: auto;
177-
}
178-
}
179-
}
180174
}
181175

182176
@mixin bar-color($color, $query: feature-targeting.all()) {
@@ -276,46 +270,80 @@
276270
}
277271
}
278272

273+
/// @deprecated - this will soon be removed in favor of auto-reversal in RTL.
279274
@mixin reversed_($query: feature-targeting.all()) {
280275
$feat-structure: feature-targeting.create-target($query, structure);
281-
$feat-animation: feature-targeting.create-target($query, animation);
282276

283277
&--reversed {
284-
.mdc-linear-progress__bar {
278+
@include _rtl-styles($query: $query);
279+
280+
.mdc-linear-progress__buffer-dots {
285281
@include feature-targeting.targets($feat-structure) {
286-
right: 0;
287-
transform-origin: center right;
282+
order: 0;
288283
}
289284
}
290285

291-
&.mdc-linear-progress--animation-ready {
292-
.mdc-linear-progress__primary-bar {
293-
@include feature-targeting.targets($feat-animation) {
294-
animation-name: mdc-linear-progress-primary-indeterminate-translate-reverse;
295-
}
286+
.mdc-linear-progress__buffer-bar {
287+
@include feature-targeting.targets($feat-structure) {
288+
order: 1;
296289
}
290+
}
291+
}
292+
}
297293

298-
.mdc-linear-progress__secondary-bar {
299-
@include feature-targeting.targets($feat-animation) {
300-
animation-name: mdc-linear-progress-secondary-indeterminate-translate-reverse;
301-
}
294+
@mixin _rtl-styles($query: $query) {
295+
$feat-structure: feature-targeting.create-target($query, structure);
296+
$feat-animation: feature-targeting.create-target($query, animation);
297+
298+
.mdc-linear-progress__bar {
299+
@include feature-targeting.targets($feat-structure) {
300+
/* @noflip */
301+
right: 0;
302+
/* @noflip */
303+
transform-origin: center right;
304+
}
305+
}
306+
307+
&.mdc-linear-progress--animation-ready {
308+
.mdc-linear-progress__primary-bar {
309+
@include feature-targeting.targets($feat-animation) {
310+
animation-name: mdc-linear-progress-primary-indeterminate-translate-reverse;
302311
}
303312
}
304313

305-
.mdc-linear-progress__buffer-dots {
314+
.mdc-linear-progress__secondary-bar {
306315
@include feature-targeting.targets($feat-animation) {
307-
animation: mdc-linear-progress-buffering-reverse 250ms infinite linear;
316+
animation-name: mdc-linear-progress-secondary-indeterminate-translate-reverse;
308317
}
318+
}
319+
}
309320

321+
.mdc-linear-progress__buffer-dots {
322+
@include feature-targeting.targets($feat-animation) {
323+
animation: mdc-linear-progress-buffering-reverse 250ms infinite linear;
324+
}
325+
326+
@include feature-targeting.targets($feat-structure) {
327+
transform: rotate(0);
328+
}
329+
}
330+
331+
&.mdc-linear-progress--indeterminate {
332+
.mdc-linear-progress__primary-bar {
310333
@include feature-targeting.targets($feat-structure) {
311-
order: 0;
312-
transform: rotate(0);
334+
/* @noflip */
335+
right: -145.166611%;
336+
/* @noflip */
337+
left: auto;
313338
}
314339
}
315340

316-
.mdc-linear-progress__buffer-bar {
341+
.mdc-linear-progress__secondary-bar {
317342
@include feature-targeting.targets($feat-structure) {
318-
order: 1;
343+
/* @noflip */
344+
right: -54.888891%;
345+
/* @noflip */
346+
left: auto;
319347
}
320348
}
321349
}

packages/mdc-linear-progress/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@material/base": "^9.0.0",
2323
"@material/feature-targeting": "^9.0.0",
2424
"@material/progress-indicator": "^9.0.0",
25+
"@material/rtl": "^9.0.0",
2526
"@material/theme": "^9.0.0",
2627
"tslib": "^1.9.3"
2728
},

0 commit comments

Comments
 (0)