Skip to content

Commit 6376a3b

Browse files
committed
add @html for formatters to be styled
resolves #128
1 parent d963e00 commit 6376a3b

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/RangePips.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
// formatting props
2222
export let prefix = "";
2323
export let suffix = "";
24-
export let formatter = (v,i) => v;
24+
export let formatter = (v,i,p) => v;
2525
2626
// stylistic props
2727
export let focus = undefined;
@@ -210,7 +210,7 @@
210210
>
211211
{#if all === 'label' || first === 'label'}
212212
<span class="pipVal">
213-
{#if prefix}<span class="pipVal-prefix">{prefix}</span>{/if}{formatter(fixFloat(min),0,0)}{#if suffix}<span class="pipVal-suffix">{suffix}</span>{/if}
213+
{#if prefix}<span class="pipVal-prefix">{prefix}</span>{/if}{@html formatter(fixFloat(min),0,0)}{#if suffix}<span class="pipVal-suffix">{suffix}</span>{/if}
214214
</span>
215215
{/if}
216216
</span>
@@ -229,7 +229,7 @@
229229
>
230230
{#if all === 'label' || rest === 'label'}
231231
<span class="pipVal">
232-
{#if prefix}<span class="pipVal-prefix">{prefix}</span>{/if}{formatter(pipVal(i),i,percentOf(pipVal(i)))}{#if suffix}<span class="pipVal-suffix">{suffix}</span>{/if}
232+
{#if prefix}<span class="pipVal-prefix">{prefix}</span>{/if}{@html formatter(pipVal(i),i,percentOf(pipVal(i)))}{#if suffix}<span class="pipVal-suffix">{suffix}</span>{/if}
233233
</span>
234234
{/if}
235235
</span>
@@ -248,7 +248,7 @@
248248
>
249249
{#if all === 'label' || last === 'label'}
250250
<span class="pipVal">
251-
{#if prefix}<span class="pipVal-prefix">{prefix}</span>{/if}{formatter(fixFloat(max),pipCount,100)}{#if suffix}<span class="pipVal-suffix">{suffix}</span>{/if}
251+
{#if prefix}<span class="pipVal-prefix">{prefix}</span>{/if}{@html formatter(fixFloat(max),pipCount,100)}{#if suffix}<span class="pipVal-suffix">{suffix}</span>{/if}
252252
</span>
253253
{/if}
254254
</span>

src/RangeSlider.svelte

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,17 @@
387387
}
388388
}
389389
390+
/**
391+
* helper to take a string of html and return only the text
392+
* @param {string} possibleHtml the string that may contain html
393+
* @return {string} the text from the input
394+
*/
395+
function pureText(possibleHtml) {
396+
const div = document.createElement("div");
397+
div.innerHTML = possibleHtml;
398+
return div.textContent || div.innerText || "";
399+
}
400+
390401
/**
391402
* when the user has unfocussed (blurred) from the
392403
* slider, deactivate all handles
@@ -832,7 +843,7 @@
832843
aria-valuemin={range === true && index === 1 ? values[0] : min}
833844
aria-valuemax={range === true && index === 0 ? values[1] : max}
834845
aria-valuenow={value}
835-
aria-valuetext="{prefix}{handleFormatter(value,index,percentOf(value))}{suffix}"
846+
aria-valuetext="{prefix}{pureText(handleFormatter(value,index,percentOf(value)))}{suffix}"
836847
aria-orientation={vertical ? 'vertical' : 'horizontal'}
837848
aria-disabled={disabled}
838849
{disabled}
@@ -841,7 +852,7 @@
841852
<span class="rangeNub" />
842853
{#if float}
843854
<span class="rangeFloat">
844-
{#if prefix}<span class="rangeFloat-prefix">{prefix}</span>{/if}{handleFormatter(value,index,percentOf(value))}{#if suffix}<span class="rangeFloat-suffix">{suffix}</span>{/if}
855+
{#if prefix}<span class="rangeFloat-prefix">{prefix}</span>{/if}{@html handleFormatter(value,index,percentOf(value))}{#if suffix}<span class="rangeFloat-suffix">{suffix}</span>{/if}
845856
</span>
846857
{/if}
847858
</span>

0 commit comments

Comments
 (0)