]> BookStack Code Mirror - bookstack/blob - resources/js/components/user-select.js
TS: Converted dom and keyboard nav services
[bookstack] / resources / js / components / user-select.js
1 import {onChildEvent} from '../services/dom.ts';
2 import {Component} from './component';
3
4 export class UserSelect extends Component {
5
6     setup() {
7         this.container = this.$el;
8         this.input = this.$refs.input;
9         this.userInfoContainer = this.$refs.userInfo;
10
11         onChildEvent(this.container, 'a.dropdown-search-item', 'click', this.selectUser.bind(this));
12     }
13
14     selectUser(event, userEl) {
15         event.preventDefault();
16         this.input.value = userEl.getAttribute('data-id');
17         this.userInfoContainer.innerHTML = userEl.innerHTML;
18         this.input.dispatchEvent(new Event('change', {bubbles: true}));
19         this.hide();
20     }
21
22     hide() {
23         /** @var {Dropdown} * */
24         const dropdown = window.$components.firstOnElement(this.container, 'dropdown');
25         dropdown.hide();
26     }
27
28 }