mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-11-17 21:33:16 +08:00
8dea99e600
* Render basic input * Make each cell type a separate struct * Add operation to set input value * Prototype communication * Make input name editable * Refactoring * Unify cell attribute setters * IO tests * Document input communication protocol in Runtime * Add more tests * Add persistence * Fix status update on cell attributes change * Rework persistence * Integrate input cell with insert mode * Add missing users keybinding * Mimic autofocus for dynamically inserted elements * Support input type selection * Support URL input and set up validation * Convert input error into a more meaningful io error * Add missing client checks * Consume every input only once per evaluation * Fixes
27 lines
506 B
JavaScript
27 lines
506 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;
|
|
},
|
|
};
|
|
|
|
export default FocusOnUpdate;
|