feat(slider): Allow users to manually set custom min & max values on slider thumbs
- 主要言語
- TypeScript
- スター
- 25k
- フォーク
- 6.8k
- 平均マージ
- 1日 8時間
- マージ済み PR(30日)
- 91
説明
### Is this a regression?
- [ ] Yes, this behavior used to work in the previous version
### The previous version in which this bug was not present was
_No response_
### Description
This is somewhat similar to an older issue with mat-checkbox (https://github.com/angular/components/issues/22149)
I want to ensure that the range in the slider is always greater than zero. E.g. if the "end" value is currently 9, then a user can only move the "start" thumb as high as 8.
I'm enforcing it by subscribing to `valueChanges` of the form controls associated with the slider input elements.
```
this.start.valueChanges.subscribe(() => {
if (this.start.value >= this.end.value) {
this.start.setValue(this.end.value - 1, { emitEvent: false });
}
});
```
Even though the code above guarantees the form control values satisfy the constraint, the underlying DOM `input` element doesn't reflect the programmatic change from the `setValue` call.
A workaround I'm currently using is injecting the `input` elements (via `@ViewChild`) and setting its `.value` directly.
### Reproduction
StackBlitz link: https://stackblitz.com/edit/benvwf-lmrtl4?file=src%2Fexample%2Fslider-range-example.ts
Steps to reproduce:
1. Drag the "start" thumb all the way to the right
### Expected Behavior
The "start" thumb stops at the "8" tick mark, never reaches the last "9".
### Actual Behavior
- The "start" thumb goes up to the "end" position ("9").
- The form control value (printed above the slider) shows "8" - out of sync with the actual thumb state in the DOM
### Environment
- Angular: 16
- CDK/Material: 16
- Browser(s): Firefox
- Operating System (e.g. Windows, macOS, Ubuntu): macOS
コントリビューションガイド
調査の方向性
リンクされた StackBlitz の再現から始め、slider の開始および終了フォームコントロールが setValue(..., { emitEvent: false }) の後に基盤となる input 要素をどのように更新するかを追跡します。fix によって thumb の位置、DOM の値、フォームコントロールの値の同期が維持され、開始値が終了値より小さい状態が確実に保たれることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- angular, typescript
- 領域
- frontend
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100