mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-12-29 03:20:46 +08:00
fix: getting value of select elements not working at all
!nuf closes #7244
This commit is contained in:
parent
91d64dc920
commit
89e7e68f70
1 changed files with 12 additions and 4 deletions
|
|
@ -450,11 +450,19 @@ export class ElementWithUtils<T extends HTMLElement = HTMLElement> {
|
|||
return new ElementWithUtils(wrapperElement as T);
|
||||
}
|
||||
|
||||
private hasValue(): this is ElementWithUtils<ElementWithValue> {
|
||||
return (
|
||||
this.native instanceof HTMLInputElement ||
|
||||
this.native instanceof HTMLTextAreaElement ||
|
||||
this.native instanceof HTMLSelectElement
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set value of input or textarea to a string.
|
||||
*/
|
||||
setValue(this: ElementWithUtils<ElementWithValue>, value: string): this {
|
||||
if (this.native instanceof HTMLInputElement) {
|
||||
if (this.hasValue()) {
|
||||
this.native.value = value;
|
||||
}
|
||||
return this as unknown as this;
|
||||
|
|
@ -465,10 +473,10 @@ export class ElementWithUtils<T extends HTMLElement = HTMLElement> {
|
|||
* @returns The value of the element, or undefined if the element is not an input or textarea.
|
||||
*/
|
||||
getValue(this: ElementWithUtils<ElementWithValue>): string | undefined {
|
||||
if (!(this.native instanceof HTMLInputElement)) {
|
||||
return undefined;
|
||||
if (this.hasValue()) {
|
||||
return this.native.value;
|
||||
}
|
||||
return this.native.value;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue