Skip to content

Commit aaf9ad2

Browse files
authored
fix(material-experimental/mdc-slider): make small fixes needed to imp… (#22684)
* fix(material-experimental/mdc-slider): make small fixes needed to implement the gmat mdc slider internally * change imports of @material/base to @material/base/types * explicitly check attributes when calling setAttribute to prevent xss * fixup! fix(material-experimental/mdc-slider): make small fixes needed to implement the gmat mdc slider internally * fixup! fix(material-experimental/mdc-slider): make small fixes needed to implement the gmat mdc slider internally * fixup! fix(material-experimental/mdc-slider): make small fixes needed to implement the gmat mdc slider internally
1 parent 481f71f commit aaf9ad2

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

rollup-globals.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ ROLLUP_GLOBALS = {
4040
"@material/animation": "mdc.animation",
4141
"@material/auto-init": "mdc.autoInit",
4242
"@material/base": "mdc.base",
43+
# This UMD module name would not match with anything that MDC provides, but we just
44+
# add this to make the linter happy. This module resolves to a type-only file anyways.
45+
"@material/base/types": "mdc.base.types",
4346
"@material/checkbox": "mdc.checkbox",
4447
"@material/circular-progress": "mdc.circularProgress",
4548
"@material/chips": "mdc.chips",

src/material-experimental/mdc-slider/global-change-and-input-listener.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {DOCUMENT} from '@angular/common';
1010
import {Inject, Injectable, NgZone, OnDestroy} from '@angular/core';
11-
import {SpecificEventListener} from '@material/base';
11+
import {SpecificEventListener} from '@material/base/types';
1212
import {fromEvent, Observable, Subject, Subscription} from 'rxjs';
1313
import {finalize, share, takeUntil} from 'rxjs/operators';
1414

src/material-experimental/mdc-slider/slider.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import {
5151
RippleRef,
5252
RippleState,
5353
} from '@angular/material/core';
54-
import {SpecificEventListener, EventType} from '@material/base';
54+
import {SpecificEventListener, EventType} from '@material/base/types';
5555
import {MDCSliderAdapter, MDCSliderFoundation, Thumb, TickMark} from '@material/slider';
5656
import {Subscription} from 'rxjs';
5757
import {GlobalChangeAndInputListener} from './global-change-and-input-listener';
@@ -977,7 +977,34 @@ class SliderAdapter implements MDCSliderAdapter {
977977
return this._delegate._getInputElement(thumbPosition).getAttribute(attribute);
978978
}
979979
setInputAttribute = (attribute: string, value: string, thumbPosition: Thumb): void => {
980-
this._delegate._getInputElement(thumbPosition).setAttribute(attribute, value);
980+
const input = this._delegate._getInputElement(thumbPosition);
981+
982+
// TODO(wagnermaciel): remove this check once this component is
983+
// added to the internal allowlist for calling setAttribute.
984+
985+
// Explicitly check the attribute we are setting to prevent xss.
986+
switch (attribute) {
987+
case 'aria-valuetext':
988+
input.setAttribute('aria-valuetext', value);
989+
break;
990+
case 'disabled':
991+
input.setAttribute('disabled', value);
992+
break;
993+
case 'min':
994+
input.setAttribute('min', value);
995+
break;
996+
case 'max':
997+
input.setAttribute('max', value);
998+
break;
999+
case 'value':
1000+
input.setAttribute('value', value);
1001+
break;
1002+
case 'step':
1003+
input.setAttribute('step', value);
1004+
break;
1005+
default:
1006+
throw Error(`Tried to set invalid attribute ${attribute} on the mdc-slider.`);
1007+
}
9811008
}
9821009
removeInputAttribute = (attribute: string, thumbPosition: Thumb): void => {
9831010
this._delegate._getInputElement(thumbPosition).removeAttribute(attribute);

0 commit comments

Comments
 (0)