BookStack/resources/js/components/user-select.js
Dan Brown 209fa04752
Some checks failed
lint-js / build (push) Has been cancelled
test-js / build (push) Has been cancelled
TS: Converted dom and keyboard nav services
2024-10-11 21:55:51 +01:00

29 lines
837 B
JavaScript

import {onChildEvent} from '../services/dom.ts';
import {Component} from './component';
export class UserSelect extends Component {
setup() {
this.container = this.$el;
this.input = this.$refs.input;
this.userInfoContainer = this.$refs.userInfo;
onChildEvent(this.container, 'a.dropdown-search-item', 'click', this.selectUser.bind(this));
}
selectUser(event, userEl) {
event.preventDefault();
this.input.value = userEl.getAttribute('data-id');
this.userInfoContainer.innerHTML = userEl.innerHTML;
this.input.dispatchEvent(new Event('change', {bubbles: true}));
this.hide();
}
hide() {
/** @var {Dropdown} * */
const dropdown = window.$components.firstOnElement(this.container, 'dropdown');
dropdown.hide();
}
}