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

feat(range): adding the resolution property for the range #9098

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
20 changes: 18 additions & 2 deletions src/components/range/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ export class Range extends Ion implements AfterViewInit, ControlValueAccessor, O
_min: number = 0;
_max: number = 100;
_step: number = 1;
_resolution: number = 0;
_snaps: boolean = false;

_debouncer: TimeoutDebouncer = new TimeoutDebouncer(0);
Expand Down Expand Up @@ -249,6 +250,20 @@ export class Range extends Ion implements AfterViewInit, ControlValueAccessor, O
*/
id: string;

/**
* @input {number} Resolution for the step. Defaults to `0`.
*/
@Input()
get resolution(): number {
return this._resolution;
}
set resolution(val: number) {
val = Math.round(val);
if (!isNaN(val)) {
this._resolution = val;
}
}

/**
* @input {number} Minimum integer value of the range. Defaults to `0`.
*/
Expand All @@ -263,6 +278,7 @@ export class Range extends Ion implements AfterViewInit, ControlValueAccessor, O
}
}


/**
* @input {number} Maximum integer value of the range. Defaults to `100`.
*/
Expand Down Expand Up @@ -602,8 +618,8 @@ export class Range extends Ion implements AfterViewInit, ControlValueAccessor, O
* @private
*/
ratioToValue(ratio: number) {
ratio = Math.round(((this._max - this._min) * ratio));
ratio = Math.round(ratio / this._step) * this._step + this._min;
ratio = parseFloat(((this._max - this._min) * ratio).toFixed(this.resolution));
ratio = parseFloat(((ratio / this._step) * this._step + this._min).toFixed(this.resolution));
return clamp(this._min, ratio, this._max);
}

Expand Down
5 changes: 5 additions & 0 deletions src/components/range/test/basic/page1.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
<ion-content>

<ion-list>
<ion-item>
<ion-label>step="0.01" max="10" min="0" pin="true" resolution="2"</ion-label>
<ion-range [(ngModel)]="singleValue" color="danger" pin="true" (ionChange)="rangeChange($event)" resolution="2" step="0.01" min="1" max="10"></ion-range>
</ion-item>


<ion-item>
<ion-label>step="5199" max="5199" min="2499" snaps="true"</ion-label>
Expand Down