-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add simple CycleButton and use it in three way checkboxes #1296
Add simple CycleButton and use it in three way checkboxes #1296
Conversation
extends Omit<ActionableButtonProps, "primitiveType"> { | ||
noState?: boolean; | ||
value?: string; | ||
onInterract?: () => void; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The prop name onInterract
contains a typo and should be spelled onInteract
(single 't'). This change would align with standard React naming conventions and correct spelling.
Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.
onInterract(); | ||
} | ||
}} | ||
onChange={onValueChange ? () => onValueChange(currentValue) : undefined} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The onChange
handler should be moved inside the onClick
handler and called after setCurrentValue
. Since setCurrentValue
is asynchronous, the current implementation will pass the old value to onValueChange
. Moving it after setCurrentValue
ensures the new value is passed correctly.
Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
9502128
to
0c5e861
Compare
onCheckedChange={() => toggleCategory(c.id)} | ||
className={styles.checkbox} | ||
<CycleButton | ||
onInterract={() => toggleCategory(c.id)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The prop name onInterract
contains a typo and should be onInteract
to match the component's interface definition. This will prevent TypeScript errors and maintain consistency with the CycleButton
component's API.
Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.
onClick={() => { | ||
if (options && options.length > 0) { | ||
const currentValueIndex = options?.indexOf(currentValue); | ||
if ( | ||
currentValueIndex === -1 || | ||
currentValueIndex === options.length - 1 | ||
) { | ||
setCurrentValue(options[0]); | ||
} else { | ||
setCurrentValue(options[currentValueIndex + 1]); | ||
} | ||
} | ||
if (onInteract) { | ||
onInteract(); | ||
} | ||
if (onValueChange) { | ||
onValueChange(currentValue); | ||
} | ||
}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The onValueChange
callback is receiving the previous state value because currentValue
hasn't been updated when the callback runs. To fix this, calculate the next value once, then use it for both setCurrentValue
and onValueChange
. This ensures the callback receives the correct new value.
Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.
0c5e861
to
3cb6694
Compare
let newValue = ""; | ||
if (options && options.length > 0) { | ||
const currentValueIndex = options?.indexOf(currentValue); | ||
if ( | ||
currentValueIndex === -1 || | ||
currentValueIndex === options.length - 1 | ||
) { | ||
newValue = options[0]; | ||
} else { | ||
newValue = options[currentValueIndex + 1]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The newValue
calculation should preserve currentValue
when options
is undefined or empty, rather than defaulting to an empty string. Currently, the code will set newValue = ""
in these cases, which could cause unexpected state changes. Consider guarding this logic:
let newValue = currentValue;
if (options?.length > 0) {
// existing cycling logic
}
Spotted by Graphite Reviewer
Is this helpful? React 👍 or 👎 to let us know.
3cb6694
to
94efb63
Compare
No description provided.