From e938b08d8af67f4b452f0ebb0414ca00d790f787 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 1 Aug 2024 16:34:14 -0600 Subject: [PATCH] range slider step default --- .../get_range_slider_control_factory.test.tsx | 16 +++++++++++++++- .../get_range_slider_control_factory.tsx | 8 ++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/examples/controls_example/public/react_controls/data_controls/range_slider/get_range_slider_control_factory.test.tsx b/examples/controls_example/public/react_controls/data_controls/range_slider/get_range_slider_control_factory.test.tsx index 11ede73a567e5..02098f93ff6fa 100644 --- a/examples/controls_example/public/react_controls/data_controls/range_slider/get_range_slider_control_factory.test.tsx +++ b/examples/controls_example/public/react_controls/data_controls/range_slider/get_range_slider_control_factory.test.tsx @@ -204,6 +204,20 @@ describe('RangesliderControlApi', () => { }); describe('step state', () => { + test('default value provided when state.step is undefined', async () => { + const { api } = await factory.buildControl( + { + dataViewId: 'myDataViewId', + fieldName: 'myFieldName', + }, + getMockedBuildApi(uuid, factory, controlGroupApi), + uuid, + controlGroupApi + ); + const serializedState = api.serializeState() as SerializedPanelState; + expect(serializedState.rawState.step).toBe(1); + }); + test('retains value from initial state', async () => { const { api } = await factory.buildControl( { @@ -272,4 +286,4 @@ describe('RangesliderControlApi', () => { expect(setControlEditorValid).toBeCalledWith(true); }); }); -}); +}); \ No newline at end of file diff --git a/examples/controls_example/public/react_controls/data_controls/range_slider/get_range_slider_control_factory.tsx b/examples/controls_example/public/react_controls/data_controls/range_slider/get_range_slider_control_factory.tsx index 47baebdbefb1b..385a93cf7e1d5 100644 --- a/examples/controls_example/public/react_controls/data_controls/range_slider/get_range_slider_control_factory.tsx +++ b/examples/controls_example/public/react_controls/data_controls/range_slider/get_range_slider_control_factory.tsx @@ -61,7 +61,7 @@ export const getRangesliderControlFactory = ( const loadingMinMax$ = new BehaviorSubject(false); const loadingHasNoResults$ = new BehaviorSubject(false); const dataLoading$ = new BehaviorSubject(undefined); - const step$ = new BehaviorSubject(initialState.step); + const step$ = new BehaviorSubject(initialState.step ?? 1); const value$ = new BehaviorSubject(initialState.value); function setValue(nextValue: RangeValue | undefined) { value$.next(nextValue); @@ -100,7 +100,11 @@ export const getRangesliderControlFactory = ( }, { ...dataControl.comparators, - step: [step$, (nextStep: number | undefined) => step$.next(nextStep)], + step: [ + step$, + (nextStep: number | undefined) => step$.next(nextStep), + (a, b) => (a ?? 1) === (b ?? 1), + ], value: [value$, setValue], } );