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

fix(material-experimental/mdc-slider): throw error when thumb is missing #24061

Merged
merged 1 commit into from
Dec 7, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 18 additions & 14 deletions src/material-experimental/mdc-slider/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ export class MatSlider

ngAfterViewInit() {
if (typeof ngDevMode === 'undefined' || ngDevMode) {
_validateThumbs(this._isRange(), this._getThumb(Thumb.START), this._getThumb(Thumb.END));
_validateInputs(
this._isRange(),
this._getInputElement(Thumb.START),
Expand Down Expand Up @@ -1202,25 +1203,28 @@ class SliderAdapter implements MDCSliderAdapter {
};
}

/**
* Ensures that there is not an invalid configuration for the slider thumb inputs.
*/
/** Ensures that there is not an invalid configuration for the slider thumb inputs. */
function _validateInputs(
isRange: boolean,
startInputElement: HTMLInputElement,
endInputElement: HTMLInputElement,
): void {
if (isRange) {
if (!startInputElement.hasAttribute('matSliderStartThumb')) {
_throwInvalidInputConfigurationError();
}
if (!endInputElement.hasAttribute('matSliderEndThumb')) {
_throwInvalidInputConfigurationError();
}
} else {
if (!endInputElement.hasAttribute('matSliderThumb')) {
_throwInvalidInputConfigurationError();
}
const startValid = !isRange || startInputElement.hasAttribute('matSliderStartThumb');
const endValid = endInputElement.hasAttribute(isRange ? 'matSliderEndThumb' : 'matSliderThumb');

if (!startValid || !endValid) {
_throwInvalidInputConfigurationError();
}
}

/** Validates that the slider has the correct set of thumbs. */
function _validateThumbs(
isRange: boolean,
start: MatSliderVisualThumb | undefined,
end: MatSliderVisualThumb | undefined,
): void {
if (!end && (!isRange || !start)) {
_throwInvalidInputConfigurationError();
}
}

Expand Down