Fixed #1471 - Add input, focus, blur events for Checkbox

This commit is contained in:
Cagatay Civici 2021-08-25 09:58:21 +03:00
parent 53a69ebd72
commit a1cf1d4277
4 changed files with 37 additions and 19 deletions

View file

@ -45,26 +45,24 @@ const CheckboxProps = [
const CheckboxEvents = [ const CheckboxEvents = [
{ {
"name": "click", name: "click",
"description": "Callback to invoke on value click.", description: "Callback to invoke on value click.",
arguments: [
{
name: "event",
type: "object",
description: "Browser event"
}
]
}, },
{ {
"name": "change", name: "change",
"description": "Callback to invoke on value change.", description: "Callback to invoke on value change.",
arguments: [ },
{ {
name: "event", name: "input",
type: "object", description: "Callback to invoke on value change."
description: "Browser event" },
} {
] name: "focus",
description: "Callback to invoke when element receives focus."
},
{
name: "blur",
description: "Callback to invoke when element loses focus."
} }
]; ];

View file

@ -13,6 +13,9 @@ declare class Checkbox {
$emit(eventName: 'update:page', value: any): this; $emit(eventName: 'update:page', value: any): this;
$emit(eventName: 'click', event: Event): this; $emit(eventName: 'click', event: Event): this;
$emit(eventName: 'change', event: Event): this; $emit(eventName: 'change', event: Event): this;
$emit(eventName: 'input', value: boolean): this;
$emit(eventName: 'focus', event: Event): this;
$emit(eventName: 'blur', event: Event): this;
} }
export default Checkbox; export default Checkbox;

View file

@ -54,14 +54,17 @@ export default {
this.$emit('click', event); this.$emit('click', event);
this.$emit('update:modelValue', newModelValue); this.$emit('update:modelValue', newModelValue);
this.$emit('change', event); this.$emit('change', event);
this.$emit('input', newModelValue);
this.$refs.input.focus(); this.$refs.input.focus();
} }
}, },
onFocus() { onFocus() {
this.focused = true; this.focused = true;
this.$emit('focus', event);
}, },
onBlur() { onBlur() {
this.focused = false; this.focused = false;
this.$emit('blur', event);
} }
}, },
computed: { computed: {

View file

@ -97,7 +97,6 @@ export default {
</div> </div>
<h5>Events</h5> <h5>Events</h5>
<p>Any valid event such as focus and blur.</p>
<div class="doc-tablewrapper"> <div class="doc-tablewrapper">
<table class="doc-table"> <table class="doc-table">
<thead> <thead>
@ -118,6 +117,21 @@ export default {
<td>event: Browser event</td> <td>event: Browser event</td>
<td>Callback to invoke on value change.</td> <td>Callback to invoke on value change.</td>
</tr> </tr>
<tr>
<td>focus</td>
<td>event: Browser event</td>
<td>Callback to invoke when element receives focus.</td>
</tr>
<tr>
<td>blur</td>
<td>event: Browser event</td>
<td>Callback to invoke when element loses focus.</td>
</tr>
<tr>
<td>input</td>
<td>value: New value</td>
<td>Callback to invoke on value change.</td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>