Skip to content

Commit

Permalink
tooltip formatters only need a .to (#1146)
Browse files Browse the repository at this point in the history
  • Loading branch information
s-cork committed Jun 15, 2021
1 parent 59f834b commit 13d8b82
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/nouislider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ function isValidFormatter(entry: unknown): entry is Formatter {
return typeof entry === "object" && typeof (<Formatter>entry).to === "function" && typeof (<Formatter>entry).from === "function";
}

function isValidTooltipFormatter(entry: unknown): entry is Formatter {
// tooltip formatters only need a to function and not a from function
return typeof entry === "object" && typeof (<Formatter>entry).to === "function";
}

function removeElement(el: HTMLElement): void {
(el.parentElement as HTMLElement).removeChild(el);
}
Expand Down Expand Up @@ -1153,7 +1158,7 @@ function testTooltips(parsed: ParsedOptions, entry: boolean | Formatter | (boole
return;
}

if (entry === true || isValidFormatter(entry)) {
if (entry === true || isValidTooltipFormatter(entry)) {
parsed.tooltips = [];

for (let i = 0; i < parsed.handles; i++) {
Expand All @@ -1167,10 +1172,7 @@ function testTooltips(parsed: ParsedOptions, entry: boolean | Formatter | (boole
}

entry.forEach(function(formatter) {
if (
typeof formatter !== "boolean" &&
(typeof formatter !== "object" || typeof formatter.to !== "function")
) {
if (typeof formatter !== "boolean" && !isValidTooltipFormatter(formatter)) {
throw new Error("noUiSlider: 'tooltips' must be passed a formatter or 'false'.");
}
});
Expand Down

0 comments on commit 13d8b82

Please sign in to comment.