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",
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: 'click', 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;

View File

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

View File

@ -73,7 +73,6 @@ export default {
</div>
<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">
<table class="doc-table">
<thead>
@ -86,12 +85,27 @@ export default {
<tbody>
<tr>
<td>click</td>
<td>-</td>
<td>event: Browser event</td>
<td>Callback to invoke on click.</td>
</tr>
<tr>
<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>
</tr>
</tbody>