material-components / material-components-web

Modular and customizable Material Design UI components for the web
https://material.io/develop/web
MIT License
17.15k stars 2.15k forks source link

[mdc-slider] support toggling discrete state programmatically #5020

Open devversion opened 5 years ago

devversion commented 5 years ago

Feature Request

Currently the mdc-slider has two modes. Continuous and discrete. For authors of components that are based on the MDC foundations, it would be nice to be able to toggle the mode of the slider programmatically.

Currently the slider mode is determined on initialization by checking if a given class exists or not. This is not ideal as re-initializing the slider in favor of changing the internal mode (just so that track markers are rendered) is not acceptable performance-wise.

Proposed solution

Add a method to the foundation like setDiscrete(boolean)

Alternatives considered

Making the isDiscrete_ class member public. A method would not be necessary but would match up with the other public methods on the foundation.

Additional context

Related to https://github.com/angular/components/pull/16795

crisbeto commented 5 years ago

I wanted to add that we also need a public API to toggle hasTrackMarker_ dynamically as well. Currently it only checks for it once on init.