mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-09-12 20:44:12 +00:00
3202f96181
Prevented interferance with the user's action if they interacted with something below the tags, since a new row would be added on blur and hence shift down positions. For #3931
30 lines
964 B
JavaScript
30 lines
964 B
JavaScript
import {Component} from "./component";
|
|
|
|
export class TagManager extends Component {
|
|
setup() {
|
|
this.addRemoveComponentEl = this.$refs.addRemove;
|
|
this.container = this.$el;
|
|
this.rowSelector = this.$opts.rowSelector;
|
|
|
|
this.setupListeners();
|
|
}
|
|
|
|
setupListeners() {
|
|
this.container.addEventListener('input', event => {
|
|
|
|
/** @var {AddRemoveRows} **/
|
|
const addRemoveComponent = window.$components.firstOnElement(this.addRemoveComponentEl, 'add-remove-rows');
|
|
if (!this.hasEmptyRows() && event.target.value) {
|
|
addRemoveComponent.add();
|
|
}
|
|
});
|
|
}
|
|
|
|
hasEmptyRows() {
|
|
const rows = this.container.querySelectorAll(this.rowSelector);
|
|
const firstEmpty = [...rows].find(row => {
|
|
return [...row.querySelectorAll('input')].filter(input => input.value).length === 0;
|
|
});
|
|
return firstEmpty !== undefined;
|
|
}
|
|
} |