Skip to content

Commit 51461d5

Browse files
committed
Slider: Add demo for custom handle
Fixes #15023 Closes gh-1740
1 parent 57bff49 commit 51461d5

File tree

5 files changed

+60
-3
lines changed

5 files changed

+60
-3
lines changed

demos/slider/custom-handle.html

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>jQuery UI Slider - Custom handle</title>
7+
<link rel="stylesheet" href="../../themes/base/all.css">
8+
<link rel="stylesheet" href="../demos.css">
9+
<style>
10+
#custom-handle {
11+
width: 3em;
12+
height: 1.6em;
13+
top: 50%;
14+
margin-top: -.8em;
15+
text-align: center;
16+
line-height: 1.6em;
17+
}
18+
</style>
19+
<script src="../../external/requirejs/require.js"></script>
20+
<script src="../bootstrap.js">
21+
var handle = $( "#custom-handle" );
22+
$( "#slider" ).slider({
23+
create: function() {
24+
handle.text( $( this ).slider( "value" ) );
25+
},
26+
slide: function( event, ui ) {
27+
handle.text( ui.value );
28+
}
29+
});
30+
</script>
31+
</head>
32+
<body>
33+
34+
<div id="slider">
35+
<div id="custom-handle" class="ui-slider-handle"></div>
36+
</div>
37+
38+
<div class="demo-description">
39+
<p>The basic slider is horizontal and has a single handle that can be moved with the mouse or by using the arrow keys.</p>
40+
</div>
41+
</body>
42+
</html>

demos/slider/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<li><a href="range-vertical.html">Vertical range slider</a></li>
1919
<li><a href="multiple-vertical.html">Multiple sliders</a></li>
2020
<li><a href="colorpicker.html">Simple colorpicker</a></li>
21+
<li><a href="custom-handle.html">Custom handle</a></li>
2122
</ul>
2223

2324
</body>

tests/unit/slider/core.js

+12
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ QUnit.test( "markup structure", function( assert ) {
2525
assert.hasClasses( handle[ 1 ], "ui-slider-handle" );
2626
} );
2727

28+
QUnit.test( "custom handle", function( assert ) {
29+
assert.expect( 3 );
30+
31+
var element = $( "#slider-custom-handle" ).slider();
32+
var customHandle = $( ".custom-handle" );
33+
var sliderHandles = element.find( ".ui-slider-handle" );
34+
35+
assert.equal( sliderHandles.length, 1, "Only one handle" );
36+
assert.strictEqual( sliderHandles[ 0 ], customHandle[ 0 ], "Correct handle" );
37+
assert.equal( customHandle.attr( "tabIndex" ), 0, "tabIndex" );
38+
} );
39+
2840
QUnit.test( "keydown HOME on handle sets value to min", function( assert ) {
2941
assert.expect( 2 );
3042
element = $( "<div></div>" );

tests/unit/slider/slider.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
<div id="slider1"></div>
2727
<div id="slider2"></div>
28-
<div id="slider3" style="position: relative; margin: 40px; width: 217px; height: 28px;">
29-
<div class="ui-slider-handle" style="position: absolute; height: 21px; left: 0px; bottom: 0px; width: 17px;"></div>
28+
<div id="slider-custom-handle">
29+
<div class="ui-slider-handle custom-handle"></div>
3030
</div>
3131

3232
</div>

ui/widgets/slider.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ return $.widget( "ui.slider", $.ui.mouse, {
117117
this.handle = this.handles.eq( 0 );
118118

119119
this.handles.each( function( i ) {
120-
$( this ).data( "ui-slider-handle-index", i );
120+
$( this )
121+
.data( "ui-slider-handle-index", i )
122+
.attr( "tabIndex", 0 );
121123
} );
122124
},
123125

0 commit comments

Comments
 (0)