Skip to content

Commit

Permalink
range slider step default
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Aug 1, 2024
1 parent 80b45ac commit e938b08
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<RangesliderControlState>;
expect(serializedState.rawState.step).toBe(1);
});

test('retains value from initial state', async () => {
const { api } = await factory.buildControl(
{
Expand Down Expand Up @@ -272,4 +286,4 @@ describe('RangesliderControlApi', () => {
expect(setControlEditorValid).toBeCalledWith(true);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const getRangesliderControlFactory = (
const loadingMinMax$ = new BehaviorSubject<boolean>(false);
const loadingHasNoResults$ = new BehaviorSubject<boolean>(false);
const dataLoading$ = new BehaviorSubject<boolean | undefined>(undefined);
const step$ = new BehaviorSubject<number | undefined>(initialState.step);
const step$ = new BehaviorSubject<number | undefined>(initialState.step ?? 1);
const value$ = new BehaviorSubject<RangeValue | undefined>(initialState.value);
function setValue(nextValue: RangeValue | undefined) {
value$.next(nextValue);
Expand Down Expand Up @@ -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],
}
);
Expand Down

0 comments on commit e938b08

Please sign in to comment.