Skip to content

Commit f32ad73

Browse files
committed
fix(range): only have one lower/upper part at a time
1 parent a8de53e commit f32ad73

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

core/src/components/range/range.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,15 +1216,26 @@ const renderKnob = (
12161216
/**
12171217
* Returns whether the given knob is at the lower or upper position based
12181218
* on current ratios for the given knob.
1219+
*
1220+
* When both knobs have the same ratio, we only want one "lower" and one
1221+
* "upper" position so that the `lower` and `upper` parts are not applied to
1222+
* the same knob. In that case, we treat knob "A" as the lower position and
1223+
* knob "B" as the upper position.
12191224
*/
12201225
const getKnobPosition = (knob: 'A' | 'B', ratioA: number, ratioB: number, dualKnobs: boolean): 'lower' | 'upper' => {
1221-
if (dualKnobs) {
1222-
if (knob === 'A') {
1223-
return ratioA <= ratioB ? 'lower' : 'upper';
1224-
}
1225-
return ratioB <= ratioA ? 'lower' : 'upper';
1226+
if (!dualKnobs) {
1227+
return 'lower';
1228+
}
1229+
1230+
if (ratioA === ratioB) {
1231+
return knob === 'A' ? 'lower' : 'upper';
1232+
}
1233+
1234+
if (knob === 'A') {
1235+
return ratioA < ratioB ? 'lower' : 'upper';
12261236
}
1227-
return 'lower';
1237+
1238+
return ratioB < ratioA ? 'lower' : 'upper';
12281239
};
12291240

12301241
const ratioToValue = (ratio: number, min: number, max: number, step: number): number => {

0 commit comments

Comments
 (0)