-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathSearchInput.js
More file actions
54 lines (46 loc) · 1.16 KB
/
SearchInput.js
File metadata and controls
54 lines (46 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import videojs from 'video.js';
export const SearchInput = (onSearch, onClose) => {
const form = videojs.dom.createEl('form', {
className: 'vjs-visual-search-form'
});
const input = videojs.dom.createEl('input', {
className: 'vjs-visual-search-input',
type: 'text',
ariaLabel: 'Search input',
tabIndex: -1
});
const closeButton = videojs.dom.createEl('button', {
className: 'vjs-control vjs-button vjs-visual-search-close',
type: 'button',
title: 'Close search',
ariaLabel: 'Close search',
tabIndex: -1
});
// Add close icon
const closeIcon = videojs.dom.createEl('span', {
className: 'vjs-icon-close'
});
closeButton.appendChild(closeIcon);
form.appendChild(input);
form.appendChild(closeButton);
// Handle search submission
form.addEventListener('submit', (e) => {
e.preventDefault();
const query = input.value.trim();
if (query) {
onSearch(query);
}
});
// Handle close button
closeButton.addEventListener('click', (e) => {
e.preventDefault();
if (onClose) {
onClose();
}
});
return {
element: form,
input,
closeButton
};
};