MCPcopy Create free account
hub / github.com/adobe/react-spectrum / getNumberFieldProps

Function getNumberFieldProps

packages/react-aria-components/src/Slider.tsx:189–282  ·  view source on GitHub ↗
(index: number)

Source from the content-addressed store, hash-verified

187 // edits that thumb's value, and its constraints mirror the thumb's (neighboring thumbs in a range
188 // slider limit its min/max).
189 let getNumberFieldProps = (index: number): WithRef<NumberFieldProps, HTMLDivElement> => ({
190 ref: numberFieldRefCallbacks[index],
191 minValue: state.getThumbMinValue(index),
192 maxValue: state.getThumbMaxValue(index),
193 step: state.step,
194 formatOptions: props.formatOptions,
195 value: state.values[index],
196 // A thumb can be individually disabled via SliderThumb's isDisabled.
197 isDisabled: state.isDisabled || Boolean(disabledThumbs[index]),
198 // Label the NumberField with the slider's labelling ids (its Label and any aria-labelledby
199 // passed to the Slider), falling back to the slider group's id (e.g. aria-label only).
200 'aria-labelledby': groupProps['aria-labelledby'] || groupProps.id,
201 'aria-describedby': props['aria-describedby'],
202 'aria-details': props['aria-details'],
203 // In a range slider, the inputs behave like one continuous text field: pressing the arrow
204 // key in the reading direction at the end of one input's text moves the caret into the next
205 // enabled input, and vice versa at the start.
206 onKeyDown(e) {
207 if (
208 state.values.length <= 1 ||
209 e.nativeEvent.isComposing ||
210 e.altKey ||
211 e.ctrlKey ||
212 e.metaKey ||
213 e.shiftKey
214 ) {
215 return;
216 }
217
218 let target = getEventTarget(e) as Element;
219 if (target.tagName !== 'INPUT') {
220 return;
221 }
222 let input = target as HTMLInputElement;
223
224 let nextKey = direction === 'rtl' ? 'ArrowLeft' : 'ArrowRight';
225 let prevKey = direction === 'rtl' ? 'ArrowRight' : 'ArrowLeft';
226 if (
227 e.key === nextKey &&
228 index < state.values.length - 1 &&
229 input.selectionStart === input.value.length &&
230 input.selectionEnd === input.value.length
231 ) {
232 for (let next = index + 1; next < state.values.length; next++) {
233 let nextInput = numberFieldRefs.current[next]?.querySelector('input');
234 if (nextInput && !nextInput.disabled) {
235 e.preventDefault();
236 nextInput.focus();
237 nextInput.setSelectionRange(0, 0);
238 break;
239 }
240 }
241 } else if (
242 e.key === prevKey &&
243 index > 0 &&
244 input.selectionStart === 0 &&
245 input.selectionEnd === 0
246 ) {

Callers 1

Slider.tsxFile · 0.85

Calls 2

getThumbMinValueMethod · 0.80
getThumbMaxValueMethod · 0.80

Tested by

no test coverage detected