Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

feat(switch): add beforeChange props #25

Merged
merged 1 commit into from
Mar 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/switch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ export const toggle = ({ emit, props, state }) => (event) => {
return false
}

state.currentValue = state.currentValue === props.trueValue ? props.falseValue : props.trueValue
const change = () => {
state.currentValue = state.currentValue === props.trueValue ? props.falseValue : props.trueValue

emit('update:modelValue', state.currentValue)
emit('change', state.currentValue)
emit('update:modelValue', state.currentValue)
emit('change', state.currentValue)
}

props.beforeChange ? props.beforeChange(change) : change()
}

export const computedWarpClasses = ({ prefixCls, props, state }) => () => [
Expand Down