mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-11-10 17:15:09 +08:00
b3b79afed4
* Restructure hook files * Simplify app.js * Refactor hooks * Implement password toggle with JS commands
28 lines
546 B
JavaScript
28 lines
546 B
JavaScript
import { isEditableElement } from "../lib/utils";
|
|
|
|
/**
|
|
* A hook used to focus an element whenever it receives LV update.
|
|
*/
|
|
const FocusOnUpdate = {
|
|
mounted() {
|
|
this.focus();
|
|
},
|
|
|
|
updated() {
|
|
if (this.el !== document.activeElement) {
|
|
this.focus();
|
|
}
|
|
},
|
|
|
|
focus() {
|
|
if (isEditableElement(document.activeElement)) {
|
|
return;
|
|
}
|
|
|
|
this.el.focus();
|
|
this.el.selectionStart = this.el.selectionEnd = this.el.value.length;
|
|
this.el.scrollLeft = this.el.scrollWidth;
|
|
},
|
|
};
|
|
|
|
export default FocusOnUpdate;
|