Skip to content

Commit

Permalink
KAD-4064 fix checkbox move options
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbert-hernandez committed Jan 27, 2025
1 parent fcc0659 commit c99ebb5
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions src/blocks/advanced-form/fields/checkbox/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,19 @@ function FieldCheckbox({ attributes, setAttributes, isSelected, clientId, contex
updateOption(index, { selected: !options[index].selected });
};

function onOptionMoveUp(oldIndex) {
return () => {
if (oldIndex === 0) {
return;
}
onOptionMove(oldIndex, oldIndex - 1);
};
}
const onOptionMoveUp = (oldIndex) => {
if (oldIndex === 0) {
return;
}
onOptionMove(oldIndex, oldIndex - 1);
};

function onOptionMoveDown(oldIndex) {
return () => {
if (oldIndex === options.length - 1) {
return;
}
onOptionMove(oldIndex, oldIndex + 1);
};
}
const onOptionMoveDown = (oldIndex) => {
if (oldIndex === options.length - 1) {
return;
}
onOptionMove(oldIndex, oldIndex + 1);
};

function onOptionMove(oldIndex, newIndex) {
if (!options) {
Expand All @@ -149,6 +145,7 @@ function FieldCheckbox({ attributes, setAttributes, isSelected, clientId, contex
options.splice(oldIndex, 1, tmpValue);

setAttributes({ options });
setRerender(Math.random());
}

const removeOptionItem = (previousIndex) => {
Expand Down Expand Up @@ -222,15 +219,17 @@ function FieldCheckbox({ attributes, setAttributes, isSelected, clientId, contex
<div className="kadence-blocks-list-item__control-menu">
<Button
icon="arrow-up"
onClick={n === 0 ? undefined : onOptionMoveUp(n)}
onClick={() => (n === 0 ? undefined : onOptionMoveUp(n))}
className="kadence-blocks-list-item__move-up"
label={__('Move Item Up', 'kadence-blocks')}
aria-disabled={n === 0}
disabled={n === 0}
/>
<Button
icon="arrow-down"
onClick={n + 1 === options.length ? undefined : onOptionMoveDown(n)}
onClick={() =>
n + 1 === options.length ? undefined : onOptionMoveDown(n)
}
className="kadence-blocks-list-item__move-down"
label={__('Move Item Down', 'kadence-blocks')}
aria-disabled={n + 1 === options.length}
Expand Down

0 comments on commit c99ebb5

Please sign in to comment.