Fixed #1234 - Add input, focus, blur events for InputSwitch

pull/1478/head
Cagatay Civici 2021-08-25 09:30:41 +03:00
parent 51976dacda
commit b13d8d517f
4 changed files with 37 additions and 5 deletions

View File

@ -27,6 +27,18 @@ const InputSwitchEvents = [
{ {
name: "change", name: "change",
description: "Callback to invoke on value change." description: "Callback to invoke on value change."
},
{
name: "input",
description: "Callback to invoke on value change."
},
{
name: "focus",
description: "Callback to invoke when element receives focus."
},
{
name: "blur",
description: "Callback to invoke when element loses focus."
} }
]; ];

View File

@ -9,6 +9,9 @@ declare class InputSwitch {
$emit(eventName: 'update:modelValue', value: boolean): this; $emit(eventName: 'update:modelValue', value: boolean): 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 InputSwitch; export default InputSwitch;

View File

@ -29,15 +29,18 @@ export default {
this.$emit('click', event); this.$emit('click', event);
this.$emit('update:modelValue', !this.modelValue); this.$emit('update:modelValue', !this.modelValue);
this.$emit('change', event); this.$emit('change', event);
this.$emit('input', !this.modelValue);
this.$refs.input.focus(); this.$refs.input.focus();
} }
event.preventDefault(); event.preventDefault();
}, },
onFocus() { onFocus(event) {
this.focused = true; this.focused = true;
this.$emit('focus', event);
}, },
onBlur() { onBlur(event) {
this.focused = false; this.focused = false;
this.$emit('blur', event);
} }
}, },
computed: { computed: {

View File

@ -73,7 +73,6 @@ export default {
</div> </div>
<h5>Events</h5> <h5>Events</h5>
<p>Any valid event such as focus, blur and input are passed to the underlying input element. Following are the additional events to configure the component.</p>
<div class="doc-tablewrapper"> <div class="doc-tablewrapper">
<table class="doc-table"> <table class="doc-table">
<thead> <thead>
@ -86,12 +85,27 @@ export default {
<tbody> <tbody>
<tr> <tr>
<td>click</td> <td>click</td>
<td>-</td> <td>event: Browser event</td>
<td>Callback to invoke on click.</td> <td>Callback to invoke on click.</td>
</tr> </tr>
<tr> <tr>
<td>change</td> <td>change</td>
<td>-</td> <td>event: Browser event</td>
<td>Callback to invoke on value change.</td>
</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> <td>Callback to invoke on value change.</td>
</tr> </tr>
</tbody> </tbody>