-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(slider): value not updated when change outside at max
- Loading branch information
1 parent
dd4fbe3
commit 1b8cebd
Showing
4 changed files
with
34 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { clamp } from '..'; | ||
|
||
describe(clamp.name, () => { | ||
it('should return value', () => { | ||
expect(clamp(10)).toBe(10); | ||
}); | ||
|
||
it('should return lower value', () => { | ||
expect(clamp(10, 20, 30)).toBe(20); | ||
}); | ||
|
||
it('should upper value', () => { | ||
expect(clamp(40, 20, 30)).toBe(30); | ||
}); | ||
|
||
it('should return value unchanged', () => { | ||
expect(clamp(25, 20, 30)).toBe(25); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* Restricts value to a specified interval [min, max] | ||
* | ||
* @param value - value | ||
* @param min - lower end of the interval | ||
* @param max - upper end of the interval | ||
* @returns - value in interval [min, max] | ||
*/ | ||
export const clamp = (value: number, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) => { | ||
return Math.min(Math.max(min, value), max); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters