SegmentedControl: only fire onValueChange on actual changes
Prevents onValueChange from firing during initialization, which caused pushState errors before router was ready. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
83b18645c8
commit
20705cc3b2
1 changed files with 8 additions and 1 deletions
|
|
@ -37,9 +37,16 @@
|
||||||
// Provide variant to child segments via context
|
// Provide variant to child segments via context
|
||||||
setContext('segmented-control-variant', variant)
|
setContext('segmented-control-variant', variant)
|
||||||
|
|
||||||
|
// Track previous value to only fire callback on actual changes (not initialization)
|
||||||
|
let previousValue = $state<string | undefined>(undefined)
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (onValueChange && value !== undefined) {
|
if (onValueChange && value !== undefined) {
|
||||||
onValueChange(value)
|
// Only call onValueChange if value actually changed (not on initialization)
|
||||||
|
if (previousValue !== undefined && value !== previousValue) {
|
||||||
|
onValueChange(value)
|
||||||
|
}
|
||||||
|
previousValue = value
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue