@@ -12,6 +12,8 @@ import {
1212} from '@fluentui/react-utilities' ;
1313import { ArrowUp , ArrowDown , End , Enter , Escape , Home , PageDown , PageUp } from '@fluentui/keyboard-keys' ;
1414import {
15+ SpinButtonBaseProps ,
16+ SpinButtonBaseState ,
1517 SpinButtonProps ,
1618 SpinButtonState ,
1719 SpinButtonSpinState ,
@@ -41,26 +43,21 @@ const MAX_SPIN_TIME_MS = 1000;
4143const lerp = ( start : number , end : number , percent : number ) : number => start + ( end - start ) * percent ;
4244
4345/**
44- * Create the state required to render SpinButton.
45- *
46- * The returned state can be modified with hooks such as useSpinButtonStyles_unstable,
47- * before being passed to renderSpinButton_unstable.
46+ * Create the base state required to render SpinButton without design-specific props.
4847 *
49- * @param props - props from this instance of SpinButton
48+ * @param props - props from this instance of SpinButton (without appearance/size)
5049 * @param ref - reference to root HTMLElement of SpinButton
5150 */
52- export const useSpinButton_unstable = ( props : SpinButtonProps , ref : React . Ref < HTMLInputElement > ) : SpinButtonState => {
53- // Merge props from surrounding <Field>, if any
54- props = useFieldControlProps_unstable ( props , { supportsLabelFor : true , supportsRequired : true } ) ;
55-
51+ export const useSpinButtonBase_unstable = (
52+ props : SpinButtonBaseProps ,
53+ ref : React . Ref < HTMLInputElement > ,
54+ ) : SpinButtonBaseState => {
5655 const nativeProps = getPartitionedNativeProps ( {
5756 props,
5857 primarySlotTagName : 'input' ,
59- excludedPropNames : [ 'defaultValue' , 'max' , 'min' , 'onChange' , 'size' , ' value'] ,
58+ excludedPropNames : [ 'defaultValue' , 'max' , 'min' , 'onChange' , 'value' ] ,
6059 } ) ;
6160
62- const overrides = useOverrides ( ) ;
63-
6461 const {
6562 value,
6663 displayValue,
@@ -71,8 +68,6 @@ export const useSpinButton_unstable = (props: SpinButtonProps, ref: React.Ref<HT
7168 stepPage = 1 ,
7269 precision : precisionFromProps ,
7370 onChange,
74- size = 'medium' ,
75- appearance = overrides . inputDefaultAppearance ?? 'outline' ,
7671 root,
7772 input,
7873 incrementButton,
@@ -159,6 +154,7 @@ export const useSpinButton_unstable = (props: SpinButtonProps, ref: React.Ref<HT
159154 if ( inputRef . current ) {
160155 // we need to set this here using the IDL attribute directly, because otherwise the timing of the ARIA value update
161156 // is not in sync with the user-entered native input value, and some screen readers end up reading the wrong value.
157+ // eslint-disable-next-line react-compiler/react-compiler
162158 inputRef . current . ariaValueNow = newValue ;
163159 }
164160 } ;
@@ -281,9 +277,7 @@ export const useSpinButton_unstable = (props: SpinButtonProps, ref: React.Ref<HT
281277 }
282278 }
283279
284- const state : SpinButtonState = {
285- size,
286- appearance,
280+ const state : SpinButtonBaseState = {
287281 spinState : keyboardSpinState ,
288282 atBound : internalState . current . atBound ,
289283
@@ -301,7 +295,6 @@ export const useSpinButton_unstable = (props: SpinButtonProps, ref: React.Ref<HT
301295 defaultProps : {
302296 autoComplete : 'off' ,
303297 role : 'spinbutton' ,
304- appearance,
305298 type : 'text' ,
306299 ...nativeProps . primary ,
307300 } ,
@@ -310,7 +303,6 @@ export const useSpinButton_unstable = (props: SpinButtonProps, ref: React.Ref<HT
310303 incrementButton : slot . always ( incrementButton , {
311304 defaultProps : {
312305 tabIndex : - 1 ,
313- children : < ChevronUp16Regular /> ,
314306 disabled :
315307 nativeProps . primary . readOnly ||
316308 nativeProps . primary . disabled ||
@@ -324,7 +316,6 @@ export const useSpinButton_unstable = (props: SpinButtonProps, ref: React.Ref<HT
324316 decrementButton : slot . always ( decrementButton , {
325317 defaultProps : {
326318 tabIndex : - 1 ,
327- children : < ChevronDown16Regular /> ,
328319 disabled :
329320 nativeProps . primary . readOnly ||
330321 nativeProps . primary . disabled ||
@@ -359,3 +350,28 @@ export const useSpinButton_unstable = (props: SpinButtonProps, ref: React.Ref<HT
359350
360351 return state ;
361352} ;
353+
354+ /**
355+ * Create the state required to render SpinButton.
356+ *
357+ * The returned state can be modified with hooks such as useSpinButtonStyles_unstable,
358+ * before being passed to renderSpinButton_unstable.
359+ *
360+ * @param props - props from this instance of SpinButton
361+ * @param ref - reference to root HTMLElement of SpinButton
362+ */
363+ export const useSpinButton_unstable = ( props : SpinButtonProps , ref : React . Ref < HTMLInputElement > ) : SpinButtonState => {
364+ // Merge props from surrounding <Field>, if any
365+ props = useFieldControlProps_unstable ( props , { supportsLabelFor : true , supportsRequired : true } ) ;
366+
367+ const overrides = useOverrides ( ) ;
368+
369+ const { appearance = overrides . inputDefaultAppearance ?? 'outline' , size = 'medium' , ...baseProps } = props ;
370+
371+ const state = useSpinButtonBase_unstable ( baseProps , ref ) ;
372+
373+ state . incrementButton . children ??= < ChevronUp16Regular /> ;
374+ state . decrementButton . children ??= < ChevronDown16Regular /> ;
375+
376+ return { ...state , appearance, size } ;
377+ } ;
0 commit comments