Skip to content

Commit f87ec9d

Browse files
committed
Simplify API, rename name attribute
1 parent 92c7449 commit f87ec9d

File tree

2 files changed

+5
-19
lines changed

2 files changed

+5
-19
lines changed

index.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,40 +43,29 @@ class RemoteInputElement extends HTMLElement {
4343
return input instanceof HTMLInputElement || input instanceof HTMLTextAreaElement ? input : null
4444
}
4545

46-
get resultsContainer(): ?HTMLElement {
47-
return document.getElementById(this.getAttribute('aria-owns') || '')
48-
}
49-
5046
get src(): string {
5147
return this.getAttribute('src') || ''
5248
}
5349

5450
set src(url: string) {
5551
this.setAttribute('src', url)
5652
}
57-
58-
get name(): string {
59-
return this.getAttribute('name') || 'q'
60-
}
61-
62-
set name(name: string) {
63-
this.setAttribute('name', name)
64-
}
6553
}
6654

6755
async function fetchResults(remoteInput: RemoteInputElement, checkCurrentQuery: boolean = true) {
68-
if (!remoteInput.input) return
69-
const query = remoteInput.input.value
56+
const input = remoteInput.input
57+
if (!input) return
58+
const query = input.value
7059
if (checkCurrentQuery && remoteInput.currentQuery === query) return
7160
remoteInput.currentQuery = query
7261
const src = remoteInput.src
7362
if (!src) return
74-
const resultsContainer = remoteInput.resultsContainer
63+
const resultsContainer = document.getElementById(remoteInput.getAttribute('aria-owns') || '')
7564
if (!resultsContainer) return
7665

7766
const url = new URL(src, window.location.origin)
7867
const params = new URLSearchParams(url.search)
79-
params.append(remoteInput.name, query)
68+
params.append(remoteInput.getAttribute('param') || 'q', query)
8069
url.search = params.toString()
8170

8271
remoteInput.dispatchEvent(new CustomEvent('loadstart'))

index.js.flow

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
declare module '@github/remote-input-element' {
44
declare export default class RemoteInputElement extends HTMLElement {
55
get input(): ?HTMLInputElement;
6-
get resultsContainer(): ?HTMLElement;
76
get src(): string;
87
set src(url: string): void;
9-
get name(): string;
10-
set name(value: string): void;
118
}
129
}

0 commit comments

Comments
 (0)