Skip to content

Commit 58759bd

Browse files
committed
Update code and add comments on lastUserEvent
1 parent 4ccac4d commit 58759bd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/KCheckbox/index.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@
197197
if (typeof this.inputValue === 'boolean') {
198198
return this.inputValue;
199199
}
200-
return Boolean(this.inputValue !== null);
200+
return this.inputValue !== null;
201201
},
202202
set(checked) {
203203
if (Array.isArray(this.inputValue)) {
@@ -255,18 +255,22 @@
255255
methods: {
256256
toggleCheck(event) {
257257
if (!this.disabled) {
258+
// Store the event that triggered this state change (mouse or keyboard)
259+
// so it can be forwarded with the emitted `change` event.
258260
this.lastUserEvent = event || null;
259261
this.$refs.kCheckboxInput.focus();
260262
this.isChecked = !this.isChecked;
261-
this.lastUserEvent = null;
262263
}
263264
},
264265
updateInputValue(newValue) {
265266
/**
266267
* Emits change event with the new checkbox state.
267268
* Used by v-model or legacy API to keep the checkbox state in sync.
269+
* The original user event that triggered the change (if any)
270+
* is forwarded as a second argument for legacy API compatibility.
268271
*/
269272
this.$emit('change', newValue, this.lastUserEvent);
273+
this.lastUserEvent = null; // Reset after emitting the change event
270274
},
271275
markInactive() {
272276
this.isActive = false;

0 commit comments

Comments
 (0)