Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): Improve QInput and QFile nativeEl types (fix #15128) #15129

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions ui/src/components/file/QFile.json
Expand Up @@ -168,6 +168,7 @@
"desc": "DEPRECATED; Access 'nativeEl' directly; Gets the native input DOM Element",
"returns": {
"type": "Element",
"tsType": "QFileNativeElement",
"desc": "The underlying native input DOM Element"
}
}
Expand All @@ -176,6 +177,7 @@
"computedProps": {
"nativeEl": {
"type": "Element",
"tsType": "QFileNativeElement",
"desc": "The native input DOM Element",
"addedIn": "v2.10.1"
}
Expand Down
2 changes: 2 additions & 0 deletions ui/src/components/input/QInput.json
Expand Up @@ -118,6 +118,7 @@
"desc": "DEPRECATED; Access 'nativeEl' directly instead; Get the native input/textarea DOM Element",
"returns": {
"type": "Element",
"tsType": "QInputNativeElement",
"desc": "The underlying native input/textarea DOM Element"
}
}
Expand All @@ -126,6 +127,7 @@
"computedProps": {
"nativeEl": {
"type": "Element",
"tsType": "QInputNativeElement",
"desc": "The native input/textarea DOM Element",
"addedIn": "v2.10.1"
}
Expand Down
1 change: 1 addition & 0 deletions ui/types/api.d.ts
Expand Up @@ -2,6 +2,7 @@ export * from "./api/vue-prop-types";
export * from "./api/cookies";
export * from "./api/dialog";
export * from "./api/qfile";
export * from "./api/qinput";
export * from "./api/qselect";
export * from "./api/qtable";
export * from "./api/qtree";
Expand Down
5 changes: 5 additions & 0 deletions ui/types/api/qfile.d.ts
Expand Up @@ -6,3 +6,8 @@ export interface QRejectedEntry {
| "filter";
file: File;
}

export type QFileNativeElement = Omit<
Omit<HTMLInputElement, "files"> & { files: FileList },
"type"
> & { type: "file" };
27 changes: 27 additions & 0 deletions ui/types/api/qinput.d.ts
@@ -0,0 +1,27 @@
// Error on "quasar" import shown in IDE is normal, as we only have Components/Directives/Plugins types after the build step
// The import will work correctly at runtime
import { QInputProps } from "quasar";

type QInputType = NonNullable<QInputProps["type"]>;

type WithKnownType<
TElement extends HTMLInputElement | HTMLTextAreaElement,
TType extends QInputType
> = Omit<TElement, "type"> & { type: TType };

/**
* @example
* ```ts
* QInputNativeElement // HTMLInputElement | HTMLTextAreaElement
* QInputNativeElement<"textarea"> // HTMLTextAreaElement
* QInputNativeElement<"text"> // Omit<HTMLInputElement, "type"> & { type: "text" }
* QInputNativeElement<"text" | "number"> // Omit<HTMLInputElement, "type"> & { type: "text" | "number" }
* QInputNativeElement<"text" | "textarea"> // (Omit<HTMLInputElement, "type"> & { type: "text" }) | HTMLTextAreaElement
* ```
*/
export type QInputNativeElement<T extends QInputType = QInputType> =
T extends "textarea"
? WithKnownType<HTMLTextAreaElement, "textarea">
: Omit<WithKnownType<HTMLInputElement, T>, "files"> & {
files: T extends "file" ? FileList : null;
};