-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add focus/blur events to inputs
closes #181
- Loading branch information
Showing
14 changed files
with
104 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
export const DispatchFocusMixin = { | ||
data () { | ||
return {hasFocus: false} | ||
}, | ||
methods: { | ||
onMouseDown() { | ||
this._active = true | ||
}, | ||
onMouseUp () { | ||
this._active = false | ||
}, | ||
onFocusEvent () { | ||
// dispatch async to let time to other focus event to propagate | ||
setTimeout(() => this.dispatchFocusEvent(),0) | ||
}, | ||
onBlurEvent () { | ||
// dispatch async to let time to other focus event to propagate | ||
// also filtur blur if mousedown | ||
this._active || setTimeout(() => this.dispatchFocusEvent(),0) | ||
}, | ||
dispatchFocusEvent() { | ||
let hasFocus = this.$el === document.activeElement || this.$el.contains(document.activeElement); | ||
if (hasFocus != this.hasFocus) { | ||
this.$emit(hasFocus ? 'focus' : 'blur') | ||
this.hasFocus = hasFocus | ||
} | ||
} | ||
}, | ||
mounted () { | ||
this.$el.addEventListener('focusin', this.onFocusEvent) | ||
this.$el.addEventListener('focusout', this.onBlurEvent) | ||
this.$el.addEventListener('mousedown', this.onMouseDown) | ||
this.$el.addEventListener('mouseup', this.onMouseUp) | ||
}, | ||
beforeDestroy () { | ||
this.$el.removeEventListener('focusin', this.onFocusEvent) | ||
this.$el.removeEventListener('focusout', this.onBlurEvent) | ||
this.$el.removeEventListener('mousedown', this.onMouseDown) | ||
this.$el.removeEventListener('mouseup', this.onMouseUp) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters