QSelect no-option template does not work with Typescript #14669
-
What happened?When reproducing the Github example layout, everyone except for the When you click on the search bar for the first time, it should display the contents of the What did you expect to happen?When you convert the QSelect component's refs and functions to TypeScript, I would expect that the Reproduction URLhttps://github.com/engineertdog/quasar-qselect-demo How to reproduce?
FlavourQuasar CLI with Webpack (@quasar/cli | @quasar/app-webpack) AreasComponents (quasar), TypeScript Support Platforms/BrowsersFirefox Quasar info outputOperating System - Windows_NT(10.0.22621) - win32/x64
NodeJs - 18.7.0
Global packages
NPM - 8.15.0
yarn - 1.22.15
@quasar/cli - 1.3.2
@quasar/icongenie - Not installed
cordova - Not installed
Important local packages
quasar - 2.10.0 -- Build high-performance VueJS user interfaces (SPA, PWA, SSR, Mobile and Desktop) in record time
@quasar/app-webpack - 3.6.2 -- Quasar Framework App CLI with Webpack
@quasar/extras - 1.15.5 -- Quasar Framework fonts, icons and animations
eslint-plugin-quasar - Not installed
vue - 3.2.41 -- The progressive JavaScript framework for building modern web UI.
vue-router - 4.1.5
pinia - 2.0.23 -- Intuitive, type safe and flexible Store for Vue
vuex - Not installed
electron - Not installed
electron-packager - Not installed
electron-builder - Not installed
@babel/core - 7.19.3 -- Babel compiler core.
webpack - 5.74.0 -- Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.
webpack-dev-server - 4.9.3 -- Serves a webpack app. Updates the browser on changes.
workbox-webpack-plugin - Not installed
register-service-worker - 1.7.2 -- Script for registering service worker, with hooks
typescript - 4.5.5 -- TypeScript is a language for application scale JavaScript development
@capacitor/core - Not installed
@capacitor/cli - Not installed
@capacitor/android - Not installed
@capacitor/ios - Not installed
Quasar App Extensions
*None installed* Relevant log outputNo response Additional contextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 3 replies
-
please make your reproduction work and we'll reopen |
Beta Was this translation helpful? Give feedback.
-
Codesandbox doesn't work as it should. I've replaced the reproduction URL with a repository with the issue. |
Beta Was this translation helpful? Give feedback.
-
That is incorrect. There are no options upon initialization due to the line if (options.value === null) {
// load data
setTimeout(() => {
options.value = stringOptions
search.value.filter('')
}, 2000)
update()
return
} This is the example layout using vanilla JavaScript: This is the broken version using TypeScript: The only difference between the two examples are the fact that the |
Beta Was this translation helpful? Give feedback.
-
You put the if (options.value === null) {
// load data
setTimeout(() => {
options.value = stringOptions
search.value.filter('')
update()
}, 2000)
return
} |
Beta Was this translation helpful? Give feedback.
-
Here is a clean TypeScript version for anyone that may need it. import { defineComponent, ref, Ref } from "vue";
import { QSelect, QSelectProps } from "quasar";
const stringOptions = [
"quasarframework/quasar",
"quasarframework/quasar-awesome"
];
interface INavbarSearchOptions {
label: string;
}
interface INavbarSearchFilteredOptions extends INavbarSearchOptions {
type: string;
}
export default defineComponent({
name: "NavbarSearch",
setup: () => {
const search = ref(null) as Ref<QSelect | null>;
const searchText = ref("");
const options = ref<string[] | null>(null);
const filteredOptions = ref<Array<INavbarSearchOptions | INavbarSearchFilteredOptions>>([]);
const filter: QSelectProps["onFilter"] = (filterVal: string, update) => {
if (options.value === null) {
// load data
setTimeout(() => {
options.value = stringOptions;
search.value?.filter("");
}, 2000);
}
update(() => searchUpdate(filterVal));
};
const searchUpdate = (filterVal?: string) => {
if (options.value) {
if (filterVal) {
filteredOptions.value = [
{
label: filterVal,
type: "In this repository"
},
{
label: filterVal,
type: "All GitHub"
},
...options.value
.filter(op => op.toLowerCase().includes(filterVal.toLowerCase()))
.map(op => ({ label: op }))
];
} else {
filteredOptions.value = options.value.map(op => ({ label: op }));
}
}
};
return {
search,
searchText,
options,
filteredOptions,
filter,
};
}
}); |
Beta Was this translation helpful? Give feedback.
Here is a clean TypeScript version for anyone that may need it.