Skip to content

Commit 03f27a2

Browse files
mdojulien-deramond
andauthored
Docs: add example of showing dynamic range value with output (#41516)
Co-authored-by: Julien Déramond <juderamond@gmail.com>
1 parent f04b980 commit 03f27a2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

site/src/content/docs/forms/range.mdx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,27 @@ By default, range inputs “snap” to integer values. To change this, you can s
3232
<Example code={`<label for="customRange3" class="form-label">Example range</label>
3333
<input type="range" class="form-range" min="0" max="5" step="0.5" id="customRange3">`} />
3434

35+
## Output value
36+
37+
The value of the range input can be shown using the `output` element and a bit of JavaScript.
38+
39+
<Example code={`<label for="customRange4" class="form-label">Example range</label>
40+
<input type="range" class="form-range" min="0" max="100" value="50" id="customRange4">
41+
<output for="customRange4" id="rangeValue" aria-hidden="true"></output>
42+
43+
<script>
44+
// This is an example script, please modify as needed
45+
const rangeInput = document.getElementById('customRange4');
46+
const rangeOutput = document.getElementById('rangeValue');
47+
48+
// Set initial value
49+
rangeOutput.textContent = rangeInput.value;
50+
51+
rangeInput.addEventListener('input', function() {
52+
rangeOutput.textContent = this.value;
53+
});
54+
</script>`} />
55+
3556
## CSS
3657

3758
### Sass variables

0 commit comments

Comments
 (0)