Skip to content

Commit

Permalink
fix(ConfigMenu): For numer type, use the step not the index
Browse files Browse the repository at this point in the history
  • Loading branch information
HHogg committed Dec 26, 2023
1 parent 75082f6 commit 7593263
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions workspaces/package/src/ConfigMenu/ConfigMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,16 @@ const toggleValueInArray = (array: string[], value: string) => {
}
};

const getSteps = (min: number, max: number, step: number) => {
const steps = [];

for (let i = min; i <= max; i += step) {
steps.push(i);
}

return steps;
};

const __root = '__root';

export const ConfigMenu = ({
Expand Down Expand Up @@ -245,19 +255,15 @@ export const ConfigMenu = ({
)}

{isNumber(activeEntry) &&
Array.from({
length: Math.floor(
(activeEntry.max - activeEntry.min) / activeEntry.step
),
}).map(
(_, i) =>
getSteps(activeEntry.min, activeEntry.max, activeEntry.step).map(
(v) =>
isNumber(activeEntry) && (
<MenuItemCheckBox
checked={activeEntry.value === i}
key={i}
onClick={createUpdateHandler(activeEntry, i)}
checked={activeEntry.value === v}
key={v}
onClick={createUpdateHandler(activeEntry, v)}
>
{activeEntry.formatter?.(i) ?? i}
{activeEntry.formatter?.(v) ?? v}
</MenuItemCheckBox>
)
)}
Expand Down

0 comments on commit 7593263

Please sign in to comment.