1
1
import Float from "@ui5/webcomponents-base/dist/types/Float.js" ;
2
2
import { fetchI18nBundle , getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js" ;
3
+ import { isEscape } from "@ui5/webcomponents-base/dist/Keys.js" ;
3
4
import SliderBase from "./SliderBase.js" ;
4
5
5
6
// Template
@@ -82,6 +83,7 @@ class Slider extends SliderBase {
82
83
constructor ( ) {
83
84
super ( ) ;
84
85
this . _stateStorage . value = null ;
86
+ this . _setInitialValue ( "value" , null ) ;
85
87
this . i18nBundle = getI18nBundle ( "@ui5/webcomponents" ) ;
86
88
}
87
89
@@ -121,13 +123,41 @@ class Slider extends SliderBase {
121
123
const newValue = this . handleDownBase ( event ) ;
122
124
this . _valueOnInteractionStart = this . value ;
123
125
126
+ // Set initial value if one is not set previously on focus in.
127
+ // It will be restored if ESC key is pressed.
128
+ if ( this . _getInitialValue ( "value" ) === null ) {
129
+ this . _setInitialValue ( "value" , this . value ) ;
130
+ }
131
+
124
132
// Do not yet update the Slider if press is over a handle. It will be updated if the user drags the mouse.
125
133
if ( ! this . _isHandlePressed ( this . constructor . getPageXValueFromEvent ( event ) ) ) {
126
134
this . _updateHandleAndProgress ( newValue ) ;
127
135
this . updateValue ( "value" , newValue ) ;
128
136
}
129
137
}
130
138
139
+ _onfocusin ( event ) {
140
+ // Set initial value if one is not set previously on focus in.
141
+ // It will be restored if ESC key is pressed.
142
+ if ( this . _getInitialValue ( "value" ) === null ) {
143
+ this . _setInitialValue ( "value" , this . value ) ;
144
+ }
145
+ }
146
+
147
+ _onfocusout ( event ) {
148
+ // Prevent focusout when the focus is getting set within the slider internal
149
+ // element (on the handle), before the Slider' customElement itself is finished focusing
150
+ if ( this . _isFocusing ( ) ) {
151
+ this . _preventFocusOut ( ) ;
152
+ return ;
153
+ }
154
+
155
+ // Reset focus state and the stored Slider's initial
156
+ // value that was saved when it was first focused in
157
+ this . _setInitialValue ( "value" , null ) ;
158
+ }
159
+
160
+
131
161
/**
132
162
* Called when the user moves the slider
133
163
*
@@ -166,9 +196,7 @@ class Slider extends SliderBase {
166
196
* @private
167
197
*/
168
198
_isHandlePressed ( clientX ) {
169
- const sliderHandle = this . shadowRoot . querySelector ( ".ui5-slider-handle" ) ;
170
- const sliderHandleDomRect = sliderHandle . getBoundingClientRect ( ) ;
171
-
199
+ const sliderHandleDomRect = this . _sliderHandle . getBoundingClientRect ( ) ;
172
200
return clientX >= sliderHandleDomRect . left && clientX <= sliderHandleDomRect . right ;
173
201
}
174
202
@@ -187,6 +215,18 @@ class Slider extends SliderBase {
187
215
this . _handlePositionFromStart = this . _progressPercentage * 100 ;
188
216
}
189
217
218
+ _handleActionKeyPress ( event ) {
219
+ const min = this . _effectiveMin ;
220
+ const max = this . _effectiveMax ;
221
+ const currentValue = this . value ;
222
+ const newValue = isEscape ( event ) ? this . _getInitialValue ( "value" ) : this . constructor . clipValue ( this . _handleActionKeyPressBase ( event , "value" ) + currentValue , min , max ) ;
223
+
224
+ if ( newValue !== currentValue ) {
225
+ this . _updateHandleAndProgress ( newValue ) ;
226
+ this . updateValue ( "value" , newValue ) ;
227
+ }
228
+ }
229
+
190
230
get styles ( ) {
191
231
return {
192
232
progress : {
@@ -212,6 +252,10 @@ class Slider extends SliderBase {
212
252
} ;
213
253
}
214
254
255
+ get _sliderHandle ( ) {
256
+ return this . shadowRoot . querySelector ( ".ui5-slider-handle" ) ;
257
+ }
258
+
215
259
get labelItems ( ) {
216
260
return this . _labelItems ;
217
261
}
@@ -221,6 +265,10 @@ class Slider extends SliderBase {
221
265
return this . value . toFixed ( stepPrecision ) ;
222
266
}
223
267
268
+ get tabIndexProgress ( ) {
269
+ return "-1" ;
270
+ }
271
+
224
272
static async onDefine ( ) {
225
273
await fetchI18nBundle ( "@ui5/webcomponents" ) ;
226
274
}
0 commit comments