feat: remove state and let rust handle
This commit is contained in:
@@ -67,9 +67,15 @@ function ChoiceStepperList<T>({
|
||||
useEffect(() => setText(formatLabel(value)), [value, formatLabel]);
|
||||
|
||||
const step = (direction: 1 | -1) => {
|
||||
const currentIndex = index === -1 ? 0 : index;
|
||||
const nextIndex = Math.min(values.length - 1, Math.max(0, currentIndex + direction));
|
||||
if (nextIndex !== currentIndex) onChange(values[nextIndex]);
|
||||
const currentIndex = values.indexOf(value);
|
||||
|
||||
if (currentIndex === -1) return;
|
||||
|
||||
const nextIndex = currentIndex + direction;
|
||||
|
||||
if (nextIndex >= 0 && nextIndex < values.length) {
|
||||
onChange(values[nextIndex]);
|
||||
}
|
||||
};
|
||||
|
||||
const commitText = () => {
|
||||
@@ -89,6 +95,15 @@ function ChoiceStepperList<T>({
|
||||
disabled={disabled}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
onBlur={commitText}
|
||||
onWheel={(e) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (e.deltaY < 0 && canUp) {
|
||||
step(1);
|
||||
} else if (e.deltaY > 0 && canDown) {
|
||||
step(-1);
|
||||
}
|
||||
}}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') e.currentTarget.blur();
|
||||
else if (e.key === 'ArrowUp') {
|
||||
@@ -164,14 +179,24 @@ function ChoiceStepperRange({
|
||||
disabled={disabled}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
onBlur={commitText}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') e.currentTarget.blur();
|
||||
else if (e.key === 'ArrowUp') {
|
||||
e.preventDefault();
|
||||
onWheel={(e) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (e.deltaY < 0 && canUp) {
|
||||
step(1);
|
||||
} else if (e.deltaY > 0 && canDown) {
|
||||
step(-1);
|
||||
}
|
||||
}}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.currentTarget.blur();
|
||||
} else if (e.key === 'ArrowUp') {
|
||||
e.preventDefault();
|
||||
if (canUp) step(1);
|
||||
} else if (e.key === 'ArrowDown') {
|
||||
e.preventDefault();
|
||||
step(-1);
|
||||
if (canDown) step(-1);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user