# Naive UI Naive UI is a Vue 3 component library. To know how to install it, see [Installation](https://www.naiveui.com/en-US/docs/installation.md). It is fairly complete, themeable, written in typescript, not too slow. ## Fairly Complete There are more than 90 components. Hope they can help you write less code. What's more, they are all treeshakable. ## Theme Customizable We provide an advanced type safe theme system that is built with typescript. All you need is to provide a theme overrides object in JS. Then all the stuffs will be done by us. What's more, no less/sass/css variables, no webpack loaders are required. And you can try the theme editor on the bottom right of the page. ## Uses TypeScript All the stuff in Naive UI is written in TypeScript. It can work with your typescript project seamlessly. What's more, you don't need to import any CSS to use the components. ## Fast I try to make it not rather slow. At least select, tree, transfer, table and cascader work with virtual list. What's more, ..., no more. Just enjoy it. ## Community - [Discord](https://discord.gg/Pqv7Mev5Dd) - 钉钉一群 33482509 (已满) - 钉钉二群 35886835 (已满) - 钉钉三群 32377370 (已满) - 钉钉四群 8165002788 (已满) - 钉钉五群 31205022250 (已满) - 钉钉六群 62720001971 (已满) - 钉钉七群 172000005810 ## Contributing Please see [CONTRIBUTING.md](https://github.com/tusen-ai/naive-ui/blob/main/CONTRIBUTING.md). ## License Naive UI is licensed under the [MIT license](https://opensource.org/licenses/MIT). --- # Installation > Please note that naive-ui only supports Vue3. If you are using Vue2, you may look at other libraries. ## npm Use npm to install. ```bash npm i naive-ui ``` ## UMD Please refer to [Using UMD](https://www.naiveui.com/en-US/docs/umd.md). ## Fonts ```bash npm i vfonts ``` ## Icons naive-ui recommends using [xicons](https://www.xicons.org) as icon library. ## Design Resources ![](https://naive-ui.oss-accelerate.aliyuncs.com/naive-design.png) [Naive UI (Sketch)](https://naive-ui.oss-accelerate.aliyuncs.com/NaiveUI-Design-Library-en-US.sketch) --- # Usage in SFC If you want to use the Single File Component(SFC) style, you can directly import components from Naive UI or install it globally to a Vue app. ## Import Directly (Recommended) You can import a component directly and use it. In this form, only components imported will be bundled. If you want to know how to import themes and locales, please see [Import on Demand](https://www.naiveui.com/en-US/docs/import-on-demand.md). ```html ``` If you can use vue setup script, you can use it like this. ```html ``` ## Install Globally (Not Recommended) ### Install All Components No tree-shaking. Bundle will have redundant codes. If you want to install globally but don't want all components, please see [Import on Demand](https://www.naiveui.com/en-US/docs/import-on-demand.md). ```js import naive from 'naive-ui' import { createApp } from 'vue' const app = createApp(App) app.use(naive) ``` After the installation, you can use all the components in your SFC like this. ```html ``` ### Volar support (2.24.2) If you are using Volar, you can specify global component types by configuring `compilerOptions.types` in `tsconfig.json`. ```json // tsconfig.json { "compilerOptions": { // ... "types": ["naive-ui/volar"] } } ``` --- # Using UMD > **Warning** > > There is a self-closing bug in UMD version of naive. Please close tags explicitly like ``. After version `2.30.3`, you can use UMD version of naive. If you want to use a minified version of naive, use `https://unpkg.com/naive-ui@version/dist/index.prod.js` as `src`. `version` is the version of naive-ui you want to use. If you don't specify a version, latest version would be used. It's preferable to link to a specific version of the package, as always relying on the latest version may lead to breaking changes. Here's a basic [demo](https://jsbin.com/saxubitaki/1/edit?html,output): ```html
{{ message }}
``` --- # Configuring Fonts Naive UI works with [vfonts](https://github.com/07akioni/vfonts). You can use fonts from `vfonts` easily which includes general fonts and monospace fonts. Just import fonts from in your app's entry file. Then it will work. ```js // entry js file of your app // ... // General Font import 'vfonts/Lato.css' // Monospace Font import 'vfonts/FiraCode.css' // then it works // ... ``` Note: Different fonts from vfonts have different font weights. If you want to use `Lato` or `OpenSans` you need to configure the global font weight of naive-ui. ```html ``` ## Change Global Fonts by Customizing Theme If you don't use `vfont` and want change global fonts by customzing theme, you need to use `n-global-style` to achieve that. Components' font won't be responsive to `theme-overrides` without `n-global-style`. Note: Make `vfont` work without `n-global-style` is a compromised design (I think this is a correct behavior). In the next major version, global reset style won't contain font related style. They'll be all put inside `n-global-style` component. --- # Import on Demand (Tree Shaking) Naive UI supports tree shaking for components, locales and themes. By default the component theme is light, locale is enUS, and no extra imports are needed. For more info about theming, see [Customizing Theme](https://www.naiveui.com/en-US/docs/customize-theme.md). ## Import Directly ```html ``` ## Auto Import You can use the `unplugin-auto-import` plugin to automatically import APIs. If you develop using SFC, you can use the `unplugin-vue-components` plugin to automatically import components on demand.The plugin will automatically parse the components used in the template and import the components. ```ts import vue from '@vitejs/plugin-vue' import AutoImport from 'unplugin-auto-import/vite' import { NaiveUiResolver } from 'unplugin-vue-components/resolvers' import Components from 'unplugin-vue-components/vite' // vite.config.ts import { defineConfig } from 'vite' // https://vitejs.dev/config/ export default defineConfig({ plugins: [ vue(), AutoImport({ imports: [ 'vue', { 'naive-ui': [ 'useDialog', 'useMessage', 'useNotification', 'useLoadingBar' ] } ] }), Components({ resolvers: [NaiveUiResolver()] }) ] }) ``` ## Install on Demand Globally ```js import { // create naive ui create, // component NButton } from 'naive-ui' import { createApp } from 'vue' const naive = create({ components: [NButton] }) const app = createApp() app.use(naive) ``` After the installation, you can use the components you installed in SFC like this. ```html ``` --- # Supported Platforms ## Browsers IE is not supported. Modern browsers such as `Edge`, `Firefox`, `Chrome`, `Safari` are tested on the latest 2 versions. No strict tests are being implemented on other versions due to the constraint of development resources, but naive-ui is expected to work on those browsers whose version is not too old (eg. in 2 years). If you find any problems please feel free to create an issue. ## Vue Only Vue 3 (>3.0.5) is supported. ## TypeScript Requires version > 4.1. --- # Common Issues ## 1. The difference between @update:xxx and on-update:xxx ### Case 1 If you are not using `v-model:xxx` with `on-update:xxx` on the same component, there is no difference between `@update:xxx` and `on-update:xxx` when used in templates. In Naive UI, all API documents use the `on-update:xxx` format, because `@` is just a shorthand provided by Vue. If you prefer camelCase, you can use `onUpdate:xxx`. If you are using JSX, you can use `onUpdateXxx` (all `onUpdate:xxx` have an equivalent implementation of `onUpdateXxx`). ### Case 2 If you are using `v-model:xxx`, you should use `@update:xxx` on the same component. ✅ example ``. ❌ example ``. That is because `v-model:value="xxx"` will be transformed to `:onUpdate:value="xxx"`. If you are using `@update:value="yyy"` together, it will be `:onUpdate:value="[xxx, yyy]"`, and then Naive UI would take care of if. However if you are using `on-update:value="yyy"`, Vue would generate code like `:onUpdate:value="xxx" :on-update-value="yyy"` and the second one would override the first one in Vue runtime. The `v-model:value` would be broken. If you have any problems, feel free to create a PR or issue on GitHub. ## 2. How to use in Single File Component(SFC)? please see [Usage in SFC](https://www.naiveui.com/en-US/docs/usage-sfc.md) --- # Controlled manner & uncontrolled manner A component's manner can be controlled or uncontrolled. Uncontrolled manner means you only listen to its change but not control its value. Controlled manner means you control the component's value. ## Uncontrolled manner In this situation, you don't set ``'s `value` but only listen to its change. Component's value will be controlled by itself. ```html ``` ## Controlled manner In the situation, you listen to component's value & change at the same time. If you don't update `value`, component's value won't be changed. Its value is controlled by you. ```html ``` ### `v-model` A component with `v-model` works in controlled manner, since `v-model` is the same as `:model-value` and `@update:model-value`. ## Uncontrolled manner in naive-ui Different library has different behavior on how to distinguish controlled or uncontrolled manner. In naive-ui, if `value` is `undefined` or not passed, it will be uncontrolled. That is to say, if you set a component's value to `undefined` won't clear it but transform it from controlled manner to uncontrolled manner. If you need to clear it, at most time you can use `null`. ### Not only `value` Any props pair like `xxx` & `@update:xxx` can work both in controlled manner or uncontrolled manner. --- # LLMs The docs are also published as Markdown for LLMs and agents, following [llms.txt](https://llmstxt.org). ## Files | File | Content | | --- | --- | | [llms.txt](https://www.naiveui.com/llms.txt) | An index of every page, grouped as in this site's menu, each with a one-line description | | [llms-full.txt](https://www.naiveui.com/llms-full.txt) | Every page in one file | | [zh-CN/llms.txt](https://www.naiveui.com/zh-CN/llms.txt), [zh-CN/llms-full.txt](https://www.naiveui.com/zh-CN/llms-full.txt) | The same in Chinese | ## A page as Markdown Add `.md` to the address of any docs or component page, for example [/en-US/components/button.md](https://www.naiveui.com/en-US/components/button.md). Component pages include the API and the full source of every demo. The button next to each page title copies the page as Markdown, copies its Markdown link, or opens it. ## With an agent Give the agent the address of `llms.txt` (`https://www.naiveui.com/llms.txt`) and let it read the pages it needs. `llms-full.txt` holds the source of every demo, so it is large: use it with tools that index a whole file. --- # JSX & TSX ## Enable JSX & TSX For how to enable JSX & TSX, please look at your toolchain's docs. ## Use Component We recommend importing components directly when using JSX. ```js import { NButton } from 'naive-ui' import { defineComponent } from 'vue' export default defineComponent({ render() { return {{ default: () => 'Star Kirby' }} } }) ``` ## Props look like @update:\* In naive-ui, all props look like `on-update:*` has a corresponding `onUpdate*` prop (since in JSX `on-update:*` and `onUpdate:*` are not valid prop names). If you find it doesn't exist, I must have forgotten to make it. Please create an issue or PR. For example, `` in template can be written in ``. --- # Server-Sider Rendering Since naive-ui is using CSS in JS, in SSR mode it needs some extra configuration. ## Caveat When using SSR under any framework, it is essential to ensure that the project meets the following conditions: 1. During the build process, any direct or indirect references to the `@css-render/*` and `css-render` packages must have a version of `>=0.15.14`. 2. During the build process, each direct or indirect reference to any `@css-render/*` and `css-render` package should ultimately point to a single target (a package should not have multiple versions or multiple copies of the same version). You can search for `css-render` in the lock file to check for duplicate packages. Failure to meet these conditions may result in SSR build failures. If you encounter issues due to this, you can resolve the problem by directing all related packages to the same version using the `resolution` field in the `package.json` file. ## Nuxt.js See [Nuxt.js](https://www.naiveui.com/en-US/docs/nuxtjs.md). ## Vitepress See [Vitepress](https://www.naiveui.com/en-US/docs/vitepress.md). ## Vite SSG/SSE See [Vite SSG/SSE](https://www.naiveui.com/en-US/docs/vite-ssge.md). ## Vite Example If you are using Vite, please see [example](https://github.com/07akioni/naive-ui-vite-ssr). ## Webpack Example If you are using Webpack, please see [example](https://github.com/tusen-ai/naive-ui/tree/main/playground/ssr). ## Inline Style Optimization By default, naive-ui bind inline theme style on components, it may increase SSR rendered HTML size. You may use `inline-theme-disabled` prop on `n-config-provider` to disable it. For pros & cons see `n-config-provider`'s doc. ## Known Issues The following components has some bugs in SSR scene, please avoid using them if possible. We will fix them gradually. - `n-scrollbar`, `n-data-table` (It works after vue >= 3.2.36) - `n-anchor` - `n-avatar-group` - `n-watermark` - `n-affix` - `n-transfer` --- # Nuxt.js ## Caveat This document pertains to SSR (Server-Side Rendering). Please familiarize yourself with the [SSR Caveats](https://www.naiveui.com/en-US/docs/ssr.md#Caveat) before proceeding. ## Nuxt.js Demo You can refer to [example](https://github.com/07akioni/naive-ui-nuxt-demo). ## Using Nuxt Module This is the same approach which previous demo uses. Install the [module](https://github.com/07akioni/nuxtjs-naive-ui) to your Nuxt application with one command: ```bash # npm npx nuxi module add nuxtjs-naive-ui # pnpm pnpm dlx nuxi module add nuxtjs-naive-ui ``` ## Using Auto Import in Nuxt You can also use the `unplugin-auto-import` plugin to automatically import APIs and the `unplugin-vue-components` plugin to automatically import components on demand. In this case, the `nuxt.config.ts` file will have a few additional configuration lines compared to the example above. ```ts import AutoImport from 'unplugin-auto-import/vite' import { NaiveUiResolver } from 'unplugin-vue-components/resolvers' import Components from 'unplugin-vue-components/vite' // https://nuxt.com/docs/api/configuration/nuxt-config export default defineNuxtConfig({ modules: ['nuxtjs-naive-ui'], vite: { plugins: [ AutoImport({ imports: [ { 'naive-ui': [ 'useDialog', 'useMessage', 'useNotification', 'useLoadingBar' ] } ] }), Components({ resolvers: [NaiveUiResolver()] }) ] } }) ``` --- # Vitepress ## Caveat This document pertains to SSR (Server-Side Rendering). Please familiarize yourself with the [SSR Caveats](https://www.naiveui.com/en-US/docs/ssr.md#Caveat) before proceeding. ## Example This is a [demo](https://github.com/07akioni/naive-ui-vitepress-demo) for using `naive-ui` in `vitepress` with SSR enabled. You can directly use the demo. ## Key process from scratch If you want to build your own demo from scratch, follow the next steps: ### 0. Install `@css-render/vue3-ssr` Make sure its version `>=0.15.14`. ```bash # npm npm install --save-dev @css-render/vue3-ssr # pnpm pnpm install --save-dev @css-render/vue3-ssr ``` ### 1. Add this content to `.vitepress/theme/index.js` ```js // .vitepress/theme/index.js import { setup } from '@css-render/vue3-ssr' import { NConfigProvider } from 'naive-ui' import { useRoute } from 'vitepress' import DefaultTheme from 'vitepress/theme' import { defineComponent, h, inject } from 'vue' const { Layout } = DefaultTheme const CssRenderStyle = defineComponent({ setup() { const collect = inject('css-render-collect') return { style: collect() } }, render() { return h('css-render-style', { innerHTML: this.style }) } }) const VitepressPath = defineComponent({ setup() { const route = useRoute() return () => { return h('vitepress-path', null, [route.path]) } } }) const NaiveUIProvider = defineComponent({ render() { return h( NConfigProvider, { abstract: true, inlineThemeDisabled: true }, { default: () => [ h(Layout, null, { default: this.$slots.default?.() }), import.meta.env.SSR ? [h(CssRenderStyle), h(VitepressPath)] : null ] } ) } }) export default { extends: DefaultTheme, Layout: NaiveUIProvider, enhanceApp: ({ app }) => { if (import.meta.env.SSR) { const { collect } = setup(app) app.provide('css-render-collect', collect) } } } ``` ### 2. Add this content to `.vitepress/config.mts` ```ts import { defineConfig } from 'vitepress' const fileAndStyles: Record = {} export default defineConfig({ // ... vite: { ssr: { noExternal: ['naive-ui', 'date-fns', 'vueuc'] } }, postRender(context) { const styleRegex = /((.|\s)+)<\/css-render-style>/ const vitepressPathRegex = /(.+)<\/vitepress-path>/ const style = styleRegex.exec(context.content)?.[1] const vitepressPath = vitepressPathRegex.exec(context.content)?.[1] if (vitepressPath && style) { fileAndStyles[vitepressPath] = style } context.content = context.content.replace(styleRegex, '') context.content = context.content.replace(vitepressPathRegex, '') }, transformHtml(code, id) { const html = id.split('/').pop() if (!html) return const style = fileAndStyles[`/${html}`] if (style) { return code.replace(/<\/head>/, `${style}`) } } }) ``` ### 3. Start using naive-ui in your markdown file ```md ... Hello World ... ``` --- # Vite SSG/SSE ## Caveat This document pertains to SSR (Server-Side Rendering). Please familiarize yourself with the [SSR Caveats](https://www.naiveui.com/en-US/docs/ssr.md#Caveat) before proceeding. ## Setup Guide If you are using `vite-sse` or `vite-ssg`. Follow the following steps to setup `naive-ui`. ### 1. Install `naive-ui`, `@css-render/vue3-ssr` ```bash # pnpm pnpm i naive-ui @css-render/vue3-ssr # npm npm i naive-ui @css-render/vue3-ssr ``` ### 2. Modify `vite.config.ts` Add following content. If there exists content already, merge them. ```ts import { setup } from '@css-render/vue3-ssr' defineConfig({ ssr: { noExternal: ['naive-ui', 'vueuc', 'date-fns'] }, ssgOptions: { async onBeforePageRender(_, __, appCtx) { const { collect } = setup(appCtx.app) ;(appCtx as any).__collectStyle = collect return undefined }, async onPageRendered(_, renderedHTML, appCtx) { return renderedHTML.replace( /<\/head>/, `${(appCtx as any).__collectStyle()}` ) } } }) ``` Then you can using naive-ui in `vite-ssg` or `vite-sse` project. --- # Customizing theme Naive-ui provides `n-config-provider` to customize the theme. By default all of the components are light themed, without any configuration. To learn more about `n-config-provider`, see [Config Provider](https://www.naiveui.com/en-US/components/config-provider.md). ## Use dark theme Set `n-config-provider`'s `theme` prop to `darkTheme` imported from naive-ui to set dark theme inside `n-config-provider`. If `theme` is `undefined` it won't affect the theme of components inside. ```html ``` You may need to include `` if you want to apply the dark theme globally, not just to the components. To learn more, see [n-global-style](https://www.naiveui.com/en-US/docs/customize-theme.md#Sync-style-of-the-body-element). ## Get theme vars Whether it's the default light theme (`lightTheme`), the modified dark theme (`darkTheme`), or the custom theme we adjusted, you can get theme variables within the scope of the theme using [useThemeVars](https://www.naiveui.com/en-US/docs/theme.md#use-theme-vars). ## Customizing theme vars (design tokens) No CSS (Scss, Less) needed. The configured global theme variables will overwrite the theme variables that take effect on descendant components. Set `n-config-provider`'s `theme-overrides` to customize theme vars. Naive-ui exports type `GlobalThemeOverrides` to help you define `theme-overrides`. For available vars please follow the type hint of `GlobalThemeOverrides`. If you want to view more theme variables, you can view them in the edit button at the bottom right corner of the Naive UI homepage. You can modify the corresponding theme variable, you can get the themeOverrides object after export. ```html ``` ## Customizing theme vars in TypeScript If you are using ts to write code, this one is more suitable for you. ```html ``` ## Customizing component theme vars The use of component theme variables is the same as the use of global theme variables, and the component theme variables will override the global theme variables. ```html ``` ## Customizing theme vars under different themes If you want to use different theme variables on light and dark theme at the same time, you can take a look at this. ```html ``` ## Use the peers vars In many cases, another component will be reused inside a component, so the theme variable of peers appears. The theme variables related to peers have not been exposed yet. Use `GlobalThemeOverrides` to view the peers variables of the corresponding component. The specific available peers will be updated later. ```html ``` ## Sync style of the body element For the following reasons, you may need to set some styles on `document.body`. 1. Naive-ui will mount some global style that is unresponsive (to theme, not media query). For example `font-family`. The style works fine by default, however they won't change when theme is changed. 2. `n-config-provider` can't sync global style (for example, body's background color) outside it. You can use `n-global-style` to sync common global style to the body element. In the following example, `n-global-style` will sync the theme provided by `n-config-provider` to `document.body`. ```html ``` ## Theme editor Naive-ui provides a theme editor to help you edit theme and export the corresponding configuration. It can be placed inside `n-config-provider`. The theme editor is not included in global installation (`app.use(naive)`). You need to import it explicitly to use it. ```html ``` --- # Internationalization Naive-ui provides `n-config-provider` to customize the internationalization. By default, all components are in English. To learn more about `n-config-provider`, see [Config Provider](https://www.naiveui.com/en-US/components/config-provider.md). ## Configure Set `n-config-provider`'s `locale` prop to `enUS` imported from naive-ui to set Chinese theme inside `n-config-provider`. Set `n-config-provider`'s `date-locale` prop to `dateEnUS` imported from naive-ui to set Chinese theme's date inside `n-config-provider`. ```html ``` ## Supported languages PRs are welcomed for locales that are not supported yet! The following list is sorted by 'Config' column. | Language | Config | Date config | Version | | ---------------------------- | ------ | ----------- | ------- | | Afrikaans (South Africa) | afZA | dateAfZA | | | Amharic (Ethiopia) | amET | dateAmET | | | Arabic (العربية) | arDZ | dateArDZ | 2.34.0 | | Azerbaijani (Azərbaycanca) | azAZ | dateAzAZ | 2.39.0 | | Belarusian (Belarus) | beBY | dateBeBY | | | Bulgarian (Bulgaria) | bgBG | dateBgBG | | | Bengali (Bangladesh) | bnBD | dateBnBD | | | Catalan (Spain) | caES | dateCaES | | | Czech (Czechia) | csCZ | dateCsCZ | 2.38.2 | | Danish (Denmark) | daDK | dateDaDK | 2.43.0 | | German (Germany) | deDE | dateDeDE | | | Greek (Greece) | elGR | dateElGR | | | English (British) | enGB | dateEnGB | 2.25.1 | | English | enUS | dateEnUS | | | Esperanto | eo | dateEo | 2.25.2 | | Spanish (Argentina) | esAR | dateEsAR | 2.24.2 | | Spanish (Spain) | esES | dateEsES | | | Estonian | etEE | dateEtEE | 2.38.0 | | Basque (Spain) | euES | dateEuES | | | Persian | faIR | dateFaIR | 2.34.4 | | Finnish (Finland) | fiFI | dateFiFI | | | Filipino (Philippines) | filPH | dateFilPH | | | French | frFR | dateFrFR | | | Galician (Spain) | glES | dateGlES | | | Gujarati (India) | guIN | dateGuIN | | | Hebrew (Israel) | heIL | dateHeIL | | | Hindi (India) | hiIN | dateHiIN | | | Croatian (Croatia) | hrHR | dateHrHR | | | Hungarian (Hungary) | huHU | dateHuHU | | | Armenian (Armenia) | hyAM | dateHyAM | | | Bahasa Indonesia | idID | dateIdID | | | Icelandic (Iceland) | isIS | dateIsIS | | | Italiano | itIT | dateItIT | 2.24.2 | | Japanese | jaJP | dateJaJP | | | Georgian (Georgia) | kaGE | dateKaGE | | | Kazakh (Kazakhstan) | kkKZ | dateKkKZ | | | Khmer (Cambodia) | kmKH | dateKmKH | 2.41.0 | | Kannada (India) | knIN | dateKnIN | | | Korean (South Korea) | koKR | dateKoKR | 2.28.1 | | Kyrgyz (Kyrgyzstan) | kyKG | dateKyKG | | | Lao (Laos) | loLA | dateLoLA | | | Lithuanian (Lithuania) | ltLT | dateLtLT | | | Latvian (Latvia) | lvLV | dateLvLV | | | Macedonian (North Macedonia) | mkMK | dateMkMK | | | Malayalam (India) | mlIN | dateMlIN | | | Mongolian (Mongolia) | mnMN | dateMnMN | | | Marathi (India) | mrIN | dateMrIN | | | Malay (Malaysia) | msMY | dateMsMY | | | Burmese (Myanmar) | myMM | dateMyMM | | | Norwegian Bokmål (Norway) | nbNO | dateNbNO | | | Nepali (Nepal) | neNP | dateNeNP | | | Dutch (Netherlands) | nlNL | dateNlNL | 2.29.0 | | Norwegian Nynorsk (Norway) | nnNO | dateNnNO | | | Punjabi (India) | paIN | datePaIN | | | Polish (Poland) | plPL | datePlPL | 2.25.2 | | Portuguese (Brazil) | ptBR | datePtBR | 2.28.1 | | Portuguese (Portugal) | ptPT | datePtPT | | | Romansh (Switzerland) | rmCH | dateRmCH | | | Romanian (Romania) | roRO | dateRoRO | | | Russian | ruRU | dateRuRU | | | Sinhala (Sri Lanka) | siLK | dateSiLK | | | Slovak | skSK | dateSkSK | 2.25.3 | | Slovenian (Slovenia) | slSI | dateSlSI | | | Albanian (Albania) | sqAL | dateSqAL | | | Serbian (Serbia) | srRS | dateSrRS | | | Swedish | svSE | dateSvSE | 2.35.0 | | Swahili (Kenya) | swKE | dateSwKE | | | Tamil (India) | taIN | dateTaIN | | | Telugu (India) | teIN | dateTeIN | | | Thai (Thailand) | thTH | dateThTH | 2.27.0 | | Turkish | trTR | dateTrTR | 2.34.0 | | Uyghur (China) | ugCN | dateUgCN | | | Ukrainian | ukUA | dateUkUA | | | Urdu (Pakistan) | urPK | dateUrPK | | | Uzbek (Uzbekistan) | uzUZ | dateUzUZ | 2.39.0 | | Vietnamese (Vietnam) | viVN | dateViVN | 2.30.7 | | Chinese (Simplified) | zhCN | dateZhCN | | | Chinese (Traditional) | zhTW | dateZhTW | | | Zulu (South Africa) | zuZA | dateZuZA | | ## Customize the existing locale You can use `createLocale` to customize the existing locale. ```html ``` --- # Create Themed Component You may not want to use only the provided components and want to write themed components. Naive UI provides some tools for developers to create themed components easier. ## Demos ### Provide Theme Use `n-config-provider` to set the theme of all its descendant components. ```vue ``` ### Use Naive Element Naive UI has `n-element` component. See [Element](https://www.naiveui.com/en-US/components/element.md). ```vue ``` ### useThemeVars Naive UI provides `useThemeVars`. It contains common theme variables. ```vue ``` --- # Potential Style Conflict ## Style Element Position Sometimes you want to control where the style element should be inserted. For example. If you have a tailwind reset style, you don't want it to be inserted after naive-ui's style. Since it may override button's style, etc. You can create a `` element inside `head` element, then naive-ui's style will be inserted right before it. Also, naive-ui uses [vueuc](https://github.com/07akioni/vueuc). If you need, its style can be controlled by `` (generally it's not needed). ```html ``` ## About Tailwind's Preflight Style Override You may find adding a meta tag to your static html files doesn't work (naive's style would still be overriden), since your toolchain may always insert tailwind's style at the end of the head tag. In this situation, you need to insert the meta tag dynamically right before the app is mounted. ```ts const meta = document.createElement('meta') meta.name = 'naive-ui-style' document.head.appendChild(meta) vueApp.mount('#app') ``` ## Disable Preflight Style (CSS Reset) To make naive-ui work for most users out of box, mounting any component of naive would create global preflight style. However it may not be expected. If you want to disable it, using `n-config-provider` like this. ```html ``` --- # Third-Party Libraries Naive UI is a high-quality Vue component library of unified design specifications. We prefer to provide only UI components with a unified specification and visual presentation. So we recommend the following great resources from the community that complement Naive UI. If you want to contribute excellent resources, you can create a pull request of this page in naive-ui's github repo. | Resources | Descriptions | | --- | --- | | [Naive UI Admin](https://github.com/jekip/naive-ui-admin) | A free open source out-of-box UI solution for enterprise applications. | | [Admin Work](https://github.com/qingqingxuan/admin-work) | A free open source, powerful, easy to use, beautiful back-office management system solution. | | [Soybean Admin](https://github.com/honghuangdc/soybean-admin) | A beautiful vue admin template, based on Vue3 + Vite + Naive UI + TypeScript. | | [Rengar Admin](https://github.com/RengarJS/rengar-admin) | A mid-backend management system template based on Vue 3.5 + Vite 7 + TypeScript + Naive UI + Pinia + UnoCSS, which is concise without excessive encapsulation and has simple and easy-to-understand code. | | [GoView](https://github.com/dromara/go-view) | A free open source and powerful yet accessible data visualization tool. | | [Vue Naive Admin](https://github.com/zclzone/vue-naive-admin) | A lightweight backend management template base on Vue3 + Vite4 + Pinia + Unocss + Naive UI. | | [Vue Bag Admin](https://vite.itnavs.com/admin/) | 🎉vue-bag-admin,Using Vite4, Vue3, TypeScript, JavaScript construction, support a variety of writing and call, a complete framework system, responsive background management system | | [Celeris Web](https://github.com/kirklin/celeris-web) | Celeris Web, based on Vue 3 and Vite, is a free and open-source front-end framework with Naive UI components and TypeScript support, featuring a Monorepo structure. It also integrates with OpenAI, providing natural language processing capabilities for modern web development. | | [Nova admin](https://github.com/chansee97/nova-admin) | a clean and concise back-end management template based on Vue3, Vite5, Typescript, and Naive UI. It implements complete functionality in a simple way, while also considering code standards, readability, and avoiding excessive encapsulation to facilitate secondary development. | | [chatgpt-web](https://github.com/Chanzhaoyu/chatgpt-web) | ChatGPT demo web page built with Express and Vue3 | | [pro-naive-ui](https://github.com/Zheng-Changfu/pro-naive-ui) | Based on Naive UI secondary encapsulation, more functions are extended on the original components | | [vue3-dynamic-form](https://github.com/yayaluoya/vue3-dynamic-form) | A dynamic form designer based on Vue3, Naive UI, to implement a lot of basic controls, can be very convenient to customize the control. | | [astral-3d-editor](https://github.com/mlt131220/Astral3DEditor) | 3D scene building tool based on Vue3 + Naive UI + ThreeJS + Vite5 + Typescript, supporting CAD & BIM analysis, including weather system, particle system, plug-in center... | | [it-tools](https://github.com/CorentinTh/it-tools) | Developed based on Vue3 and the Naive UI component library, it brings together a variety of practical online tools | | [Lithe Admin](https://github.com/tenianon/lithe-admin) | A lightweight and elegant backend management template, built using Vue3 + Naive UI + Vite + TypeScript + Pinia, featuring a Tailwind CSS Color color scheme and a frosted texture design. | | [Vue Simple Template](https://github.com/gitboyzcf/vue3-simple-template) | A simple universal starter template based on Vue 3.5 + Vite 8 + Naive UI + TypeScript + Pinia + Vue Router + Tailwind CSS 4 + Pnpm. | --- # Avatar On the Internet, nobody knows you're a dog. ## Demos ### Size Avatar has `small`, `medium` and `large` sizes. You could also use a custom px number for size. ```vue ``` ### Shape Avatar can be `round`. ```vue ``` ### Color You can set colors related to things you want to eat. ```vue ``` ### Badge Using it with `badge` would be nice (if you like tons of notifications). ```vue ``` ### Icon I like using an icon in an avatar. ```vue ``` ### Content size Text is resized to fit the avatar. ```vue ``` ### Fallback Show 07akioni if loading fails. ```vue ``` ### Avatar Group Crowded people. --- Please note that the demo uses `NGAvatarGroup` which is available since naive-ui `2.43.0`. The `NGAvatarGroup` is the same as `NAvatarGroup` except with a generic `options` prop which can make slots & props types more accurate in Vue files. The component is only available in Vue >= `3.3` and in `.vue` files. If your environment doesn't support [Vue Generic Components](https://blog.vuejs.org/posts/vue-3-3#generic-components), please use `NAvatarGroup` instead. The `NGAvatarGroup` should be imported from `'naive-ui/generic'`. ```vue ``` ### Lazy load Load the images only after they enter the viewport. There are two ways to use it: one is to use the `lazy` property alone, which will be set to the value of the [HTMLImageElement.loading](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/loading) property, and the other is to use `lazy` together with the `intersection-observer-options` configuration to implement lazy loading using the [IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver) API. ```vue ``` ## API ### Avatar Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | bordered | `boolean` | `false` | Whether to display a avatar with border. | | | color | `string` | `undefined` | The background color of the avatar. | | | fallback-src | `string` | `undefined` | Image URL to show when avatar fails to load. | | | img-props | `ImgHTMLAttributes` | `undefined` | The props of the img element inside the component. | 2.34.0 | | intersection-observer-options | `{ root?: Element \| Document \| string \| null, rootMargin?: string, threshold?: number \| number[]; }` | `undefined` | Intersection observer's config to be applied when `lazy=true`. | 2.31.0 | | lazy | `boolean` | `false` | Load image after it enters viewport. When used alone, it will be assigned the property value of [HTMLImageElement.loading](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/loading). Alternatively, it can be used in conjunction with the `intersection-observer-options` configuration to achieve lazy loading. | 2.31.0 | | object-fit | `'fill' \| 'contain' \| 'cover' \| 'none' \| 'scale-down'` | `'fill'` | Object-fit type of the image in the container. | | | render-fallback | `() => VNodeChild` | `undefined` | Render function of fallback content. | 2.33.4 | | render-placeholder | `() => VNodeChild` | `undefined` | Render function of placeholder. | 2.33.4 | | round | `boolean` | `false` | Whether to display a rounded avatar. | | | size | `'small' \| 'medium' \| 'large' \| number` | `'medium'` | Avatar's size. | | src | `string` | `undefined` | Avatar's image source. | | | on-error | `(e: Event) => void` | `undefined` | Callback executed when the avatar image fails to load. | | ### AvatarGroup Props The generic type is `` (available since `2.43.0`). It is only supported in `.vue` files with `Vue >= 3.3`. You can use it by `importing NGAvatarGroup from 'naive-ui/generic'`. Otherwise, please use the regular `n-avatar-group` component. ```ts interface AvatarGroupOption { src: string } ``` | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | expand-on-hover | `boolean` | `false` | Expand on hover. | 2.37.0 | | max | `number` | `undefined` | Max avatar count in the group. | | | max-style | `Object \| string` | `undefined` | The style of the overflow placeholder. | | | options | `Array` | `[]` | Avatar group options. | | | size | `'small' \| 'medium' \| 'large' \| number` | `'medium'` | Avatar's size. | 2.43.0 | | vertical | `boolean` | `false` | Whether display a vertical avatar group. | | ### Avatar Slots | Name | Parameters | Description | Version | | --- | --- | --- | --- | | default | `()` | The content of the avatar. | | | fallback | `()` | Content if avatar load fails. | 2.33.4 | | placeholder | `()` | Placeholder shown when image is not loaded. | 2.31.0 | ### AvatarGroup Slots | Name | Parameters | Description | | --- | --- | --- | | avatar | `(info: { option: { src: string } })` | Avatar of the avatar group. | | default | `()` | The content of the avatar group. | | rest | `(info: { options: Array<{ src: string }>, rest: number })` | Overflow indicator of the avatar group. | --- # Button Button is used to trigger some actions. ## Demos ### Basic There are `default`, `primary`, `tertiary`, `info`, `success`, `warning` and `error` button types. ```vue ``` ### Secondary button ```vue ``` ### Tertiary button ```vue ``` ### Quaternary button ```vue ``` ### Dashed Use `dashed` to show a dashed button. ```vue ``` ### Size Buttons can be `tiny`, `small`, `medium` and `large` in size. ```vue ``` ### Text button It just looks like text. ```vue ``` ### Tag You can render buttons with different tags. For example ``. ```vue ``` ### Disabled Buttons can be disabled. ```vue ``` ### Icon Icons can be used in buttons. You can use `render-icon` prop or `icon` slot. ```vue ``` ### Events Handle events of buttons. ```vue ``` ### Shape Buttons can have different shapes. ```vue ``` ### Ghost Ghost buttons have transparent backgrounds. ```vue ``` ### Loading Buttons can have loading states. ```vue ``` ### Custom color These two colors look like a toadstool. ```vue ``` ### Button group Buttons can be grouped. ```vue ``` ### Use icons as buttons Sometimes you may want to use an icon as a button and customize its size. You can use the `text` prop and `font-size` style to set it. ```vue ``` ### Using popover in disabled state The native disabled button won't trigger some mouse events so `n-popover` can't listen to it. If you need to use it, you can use `tag` prop to change button's behavior. ```vue ``` ## API ### Button Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | attr-type | `'button' \| 'submit' \| 'reset'` | `'button'` | The `type` attribute of the button's DOM. | | | block | `boolean` | `false` | Whether the button is displayed as block. | | | bordered | `boolean` | `true` | Whether the button shows the border. | | | circle | `boolean` | `false` | Whether the button is round. | | | color | `string` | `undefined` | Button color (support `#FFF`, `#FFFFFF`, `yellow`,`rgb(0, 0, 0)` formatted colors). | | | dashed | `boolean` | `false` | Whether the button's border is a dashed line. | | | disabled | `boolean` | `false` | Whether the button is disabled. | | | focusable | `boolean` | `true` | Whether the button is focusable. | | | ghost | `boolean` | `false` | Whether the button is ghost. | | | native-focus-behavior | `boolean` | Browser is not Safari | Whether to follow button's native focus behavior. Since safari's button can't be focused by click, naive-ui uses some tricks to make it focusable on safari. If you don't need the behavior or need the button to be draggable, you can enable the prop. | 2.28.3 | | icon-placement | `'left' \| 'right'` | `'left'` | The position of the icon in the button. | | | keyboard | `boolean` | `true` | Whether is supports keyboard operation. | | | quaternary | `boolean` | `false` | Whether the button is quaternary button. | | | loading | `boolean` | `false` | Whether the button shows the loading status. | | | spin-props | `{ strokeWidth?: number, stroke?: string, scale?: number, radius?: number }` | `undefined` | Loading icon properties. | 2.44.0 | | render-icon | `() => VNodeChild` | `undefined` | Render function that renders button icon. | 2.34.0 | | round | `boolean` | `false` | Whether the button shows rounded corners. | | | secondary | `boolean` | `false` | Whether the button is secondary button. | | | size | `'tiny' \| 'small' \| 'medium' \| 'large'` | `'medium'` | Button size. | | | strong | `boolean` | `false` | Whether to use strong text in the button. | | | tertiary | `boolean` | `false` | Whether the button is tertiary button. | | | text | `boolean` | `false` | Whether to display as a text button. | | | text-color | `string` | `undefined` | Button text color (support `#FFF`, `#FFFFFF`, `yellow`,`rgb(0, 0, 0)` formatted colors). | | | type | `'default' \| 'tertiary' \| 'primary' \| 'success' \| 'info' \| 'warning' \| 'error'` | `'default'` | Button type. | | | tag | `string` | `'button'` | What tag need the button be rendered as. | | ### ButtonGroup Props | Name | Type | Default | Description | | --- | --- | --- | --- | | size | `'tiny' \| 'small' \| 'medium' \| 'large'` | `undefined` | The buttons' size in button group. If set, the button's size prop inner group won't work. | | vertical | `boolean` | `false` | Directions of buttons in the group. | ### Button Slots | Name | Parameters | Description | | ------- | ---------- | ---------------------------------- | | default | `()` | The default content of the button. | | icon | `()` | The icon of the button. | ### ButtonGroup Slots | Name | Parameters | Description | | ------- | ---------- | -------------------------------------- | | default | `()` | The button group is filled by default. | --- # Card Just put something in it. ## Demos ### Basic A basic card. ```vue ``` ### Size Card has `small`, `medium`, `large`, `huge` sizes. ```vue ``` ### Cover Card can have a cover. ```vue ``` ### Hoverable ```vue ``` ### Slots Card has many slots to help you write less code. ```vue ``` ### Border Card can be used without border. ```vue ``` ### Segmented `content`, `footer` can be segmented or `soft` segmented. `action` can be segmented. Segment border will appear at the top of segmented parts. ```vue ``` ### Closable You may need this when using it in a modal. ```vue ``` ### No title Nobody said a card must have a title. ```vue ``` ### Content Scroll Enable `content-scrollable` to keep scrolling inside the content area only. Header and footer stay fixed. It is usually used with a fixed card height. ```vue ``` ### Loading Use `n-skeleton` to simulate loading effect. ```vue ``` ### Custom Card provides `content-style`, `header-style`, `footer-style` to help you customize style. For example you want an card with no padding to put whatever you want. ```vue ``` ### Embedded effect In light mode, sometimes you may need to make background a bit darker to distinguish card from white background. ```vue ``` ## Card ### Card Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | action | `() => VNodeChild` | `undefined` | Operating area content, must be a render function. | 2.38.2 | | bordered | `boolean` | `true` | Whether to show the card border. | | | closable | `boolean` | `false` | Is it allowed to close. | | | close-focusable | `boolean` | `false` | Whether the close button can be focused. | 2.43.0 | | content | `string \| (() => VNodeChild)` | `undefined` | Card content, can be a render function. | 2.38.2 | | content-class | `string` | `undefined` | The class of the card content area. | 2.36.0 | | content-scrollable | `boolean` | `false` | Whether only the card content area is scrollable (recommended with fixed height). | 2.44.0 | | content-style | `Object \| string` | `undefined` | The style of the card content area. | | | cover | `() => VNodeChild` | `undefined` | Cover content, must be a render function. | 2.38.2 | | embedded | `boolean` | `false` | Use a darker background color to show the embedding effect (only for bright themes) | | | footer | `() => VNodeChild` | `undefined` | Footer content, must be a render function. | 2.38.2 | | footer-class | `string` | `undefined` | The class of the bottom area of the card. | 2.36.0 | | footer-style | `Object \| string` | `undefined` | The style of the bottom area of the card. | | | header-class | `string` | `undefined` | The class of the card head area. | 2.36.0 | | header-style | `Object \| string` | `undefined` | The style of the card head area. | | | header-extra | `() => VNodeChild` | `undefined` | Header extra content, must be a render function. | 2.38.2 | | header-extra-class | `string` | `undefined` | The class of the card head extra area. | 2.36.0 | | header-extra-style | `Object \| string` | `undefined` | The style of the card head extra area. | 2.25.0 | | hoverable | `boolean` | `false` | Whether to show shadow when hovering on the card. | | | segmented | `boolean \| { [part in 'content' \| 'footer' \| 'action']?: boolean \| 'soft' }` | `false` | Segment divider settings of the card. | | | size | `'small' \| 'medium' \| 'large' \| 'huge'` | `'medium'` | Card size. | | | tag | `string` | `'div'` | What tag need the card be rendered as. | 2.34.3 | | title | `string \| (() => VNodeChild)` | `undefined` | Card title. | Render function since 2.38.2 | | on-close | `() => void` | `undefined` | Callback function triggered upon closing the card. | | ### Card Slots | Name | Parameters | Description | | ------------ | ---------- | ----------------------- | | cover | `()` | Cover content. | | header | `()` | Header content. | | header-extra | `()` | Header extra content. | | default | `()` | Card content. | | footer | `()` | Footer content. | | action | `()` | Operating area content. | --- # Carousel It's usually used to display good news. ## Demos ### Basic ```vue ``` ### Arrow Set `show-arrow` to show the arrow。 ```vue ``` ### Autoplay Set `autoplay`, it can autoplay。 ```vue ``` ### Dots Set `dot-type` to change the style of the dots. You can use `:show-dots="false"` to hide the dots. Set `dot-placement` to change the position of the dots. ```vue ``` ### Vertical ```vue ``` ### Space between ```vue ``` ### Slides per view Please note that this prop will conflict with `loop`. If you need to customize the number of displays per view, then the `loop` prop will be disabled. ```vue ``` ### Auto slides per view ```vue ``` ### Centered Set `centered-slides` to center all `slides`, this is only useful when `effect` is `slide` and `card`. ```vue ``` ### Effect If you want to customize the transition effect, you can use `transition-props` and set `effect` to `custom`. ```vue ``` ### Customizing transition If you want to customize the transition effect, you can use `transition-props` and set `effect` to `'custom'`. For transition props, see [reference](https://v3.vuejs.org/api/built-in-components.html#transition). ```vue ``` ### Hover Set the `trigger` to `hover` to trigger the switch when the mouse passes over the dots. ```vue ``` ### Keyboard Whether to switch the carousel by pressing the key, it is only valid when the focus is on Dots. ```vue ``` ### Mousewheel ```vue ``` ### Simulate drag Carousel enable the `Touch` event simulation by default. If you need the carousel chart to respond to mouse drag, you can use `draggable` prop. ```vue ``` ### Customzing arrow and dots ```vue ``` ### Customize card You can use `next-slide-style` and `prev-slide-style` to adjust the ratio of front & back cards size ratio. ```vue ``` ### Custom Dots ```vue ``` ## API ### Carousel Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | autoplay | `boolean` | `false` | Whether to scroll automatically. | | | centered-slides | `boolean` | `false` | Whether to center the current view carousel. | 2.24.0 | | current-index | `number` | `undefined` | current index. | 2.24.0 | | default-index | `number` | `0` | default index. | 2.24.0 | | direction | `'horizontal' \| 'vertical'` | `'horizontal'` | Carousel shows the direction. | | | dot-placement | `'top' \| 'bottom' \| 'left' \| 'right'` | `'bottom'` | Dot placement in the panel. | 2.24.0 | | dot-type | `'dot' \| 'line'` | `'dot'` | Dot style. | 2.24.0 | | draggable | `boolean` | `false` | Whether to switch the carousel by dragging the mouse. | 2.24.0 | | effect | `'slide' \| 'fade' \| 'card' \| 'custom'` | `'slide'` | Transition effect when switching between carousel. | 2.24.0, `'card'` 2.24.2 | | interval | `number` | `5000` | Auto play interval (ms). | | | keyboard | `boolean` | `false` | Whether to switch the carousel by pressing the key, it only works when the focus is on Dots. | 2.24.0 | | loop | `boolean` | `true` | Whether to loop. | 2.24.0 | | mousewheel | `boolean` | `false` | Whether to switch the carousel through the mouse wheel. | 2.24.0 | | next-slide-style | `object \| string` | `undefined` | Next slide's style. | 2.27.0 | | prev-slide-style | `object \| string` | `undefined` | Previous slide's style. | 2.27.0 | | show-arrow | `boolean` | `false` | Whether to show arrow buttons. | 2.24.0 | | show-dots | `boolean` | `true` | Whether to show dots. | 2.24.0 | | slides-per-view | `'auto' \| number` | `1` | Number of carousels displayed on per view. | 2.24.0 | | space-between | `number` | `0` | The spacing between the carousels. | 2.24.0 | | touchable | `boolean` | `true` | Whether to switch the carousel by touch. | 2.24.0 | | transition-style | `{ transitionDuration?: string, transitionTimingFunction?: string }` | `{ transitionDuration: '300ms' }` | The style of the transition effect. | 2.24.0 | | transition-props | `TransitionProps` | `undefined` | Custom transition effect properties, [reference](https://v3.vuejs.org/api/built-in-components.html#transition). | 2.24.0 | | trigger | `'click' \| 'hover'` | `'click'` | The method of manual switching. | | | on-update:current-index | `(currentIndex: number, lastIndex: number) => void` | `undefined` | Callback function when the current index changes. | 2.24.0 | ### Carousel Slots | Name | Parameters | Description | Version | | --- | --- | --- | --- | | default | `()` | Carousel content. | | arrow | `(info: { total: number, currentIndex: number, to: (index: number) => void, prev: () => void, next: () => void })` | Arrow. | 2.24.0 | | dots | `(info: { total: number, currentIndex: number, to: (index: number) => void })` | Dots. | 2.24.0 | ### Carousel Methods | Name | Type | Description | Version | | --- | --- | --- | --- | | to | `(index: number) => void` | Slide to index. | 2.24.0 | | prev | `() => void` | Slide to previous page. | 2.24.0 | | next | `() => void` | Slide to next page. | 2.24.0 | | getCurrentIndex | `() => number` | Get current index. | 2.24.0 | --- # Collapse I saw it appears in many side control panels. ## Demos ### Basic ```vue ``` ### Arrow placement Use `arrow-placement` to set the placement of arrow. ```vue ``` ### Accordion Like an accordion. ```vue ``` ### Nested It can be nested. ```vue ``` ### Display directive Set `display-directive` to `if` or `show` to determine whether to keep the DOM inside `n-collapse-item` when inactive. ```vue ``` ### Click on item header ```vue ``` ### Customize icon ```vue ``` ### Default expanded It should be noted that even if only one panel you want to set to be expanded, `default-expanded-names` should also be passed in an array, unless `accordion` is set to `true`. ```vue ``` ### Extra info in header Put some info on the right side of the item. ```vue ``` ### Disabled ```vue ``` ### Trigger areas If you want to customize expansion trigger areas of collapse, you can use `trigger-areas` property. ```vue ``` ## API ### Collapse Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | accordion | `boolean` | `false` | Only allow one panel open at a time. | | arrow-placement | `'left' \| 'right'` | `'left'` | Arrow placement side of text. | | default-expanded-names | `string \| number \| Array \| null` | `null` | Pre-expanded panels that can still be collapsed. If `accordion` mode is set, it should be a non-array value. | | display-directive | `'if' \| 'show'` | `'if'` | The display directive to use when `n-collapse-item` renders content. `'if'` corresponds to `v-if` and `'show'` corresponds to `v-show`. | | expanded-names | `string \| number \| Array \| null` | `undefined` | Expanded panels that cannot be collapsed. If `accordion` mode is set, it should be a non-array value. | | trigger-areas | `Array<'main' \| 'arrow' \| 'extra'>` | `['main', 'arrow', 'extra']` | Expansion trigger areas. If you don't want to trigger expansion on some areas, you can use the prop. | 2.37.1 | | on-item-header-click | `(data: { name: string \| number, expanded: boolean, event: MouseEvent }) => void` | `undefined` | Callback function triggered when the title is clicked. | | on-update:expanded-names | `(expandedNames: Array \| string \| number \| null) => void` | `undefined` | Callback function triggered when the expanded-names array is changed. | ### CollapseItem Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | disabled | `boolean` | `false` | Whether the item is disabled. | 2.32.2 | | display-directive | `'if' \| 'show'` | `undefined` | The display directive to use when it is rendering its content. `'if'` corresponds to `v-if` and `'show'` corresponds to `v-show`. When it is set to `undefined` the value will follow its outer `n-collapse`. | | | name | `string \| number` | random string | Item identifier (should be unique). | | | title | `string` | `undefined` | Title. | | ### Collapse Slots | Name | Parameters | Description | | --- | --- | --- | | arrow | `(props: { collapsed: boolean })` | Custom icons for folding panels. | | default | `()` | The contents of the collapsible panel. | | header | `(props: { collapsed: boolean })` | The content of the header of the collapsed panel node. | ### CollapseItem Slots | Name | Parameters | Description | | --- | --- | --- | | arrow | `(props: { collapsed: boolean })` | The custom icon of the node header of the collapsible panel. | | default | `()` | The contents of the collapsible panel node. | | header | `(props: { collapsed: boolean })` | The content of the header of the collapsed panel node. | | header-extra | `(props: { collapsed: boolean })` | The extra content of the header of the collapsed panel node. | --- # Divider Divide something. ## Demos ### Basic ```vue ``` ### Title ```vue ``` ### Vertical ```vue ``` ## API ### Divider Props | Name | Type | Default | Description | | --- | --- | --- | --- | | dashed | `boolean` | `false` | Whether to show dashed line. | | title-placement | `'left' \| 'right' \| 'center'` | `'center'` | Title placement. | | vertical | `boolean` | `false` | Whether to show vertical direction. | ### Divider Slots | Name | Parameters | Description | | ------- | ---------- | --------------------- | | default | `()` | The title of divider. | --- # Dropdown When you have some functions to trigger. ## Demos ### Basic A basic dropdown. ```vue ``` ### Icon Dropdown options can also have icons! ```vue ``` ### Trigger Different trigger methods for dropdown. ```vue ``` ### Cascade Dropdown can be cascaded. ```vue ``` ### Arrow Show an arrow with the dropdown. ```vue ``` ### Placement Dropdown options can be aligned using the `placement` property. ```vue ``` ### Size A dropdown has different sizes. ```vue ``` ### Batch Render Note: `render-label` works for group type label, which can be set in `option.type`. ```vue ``` ### Manual Position Note: When using manual position, `trigger` must be set to `'manual'`. In addition, you need to listen to the update:show callback to update the value of show, ensuring that shortcut operations such as the Esc key can close the menu normally. ```vue ``` ### Pure Render Content You can simply render some content unrelated to option data. In this case, you can add an option with `type='render'`. ```vue ``` ### Custom Option Props Bind anything you want. ```vue ``` ### Add Tooltip for Option You can use `render-option` to add tooltip for an option. ```vue ``` ## API ### Dropdown Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | animated | `boolean` | `true` | Use an animation when showing options. | | | inverted | `boolean` | `false` | Use the inverted style. | | | children-field | `string` | `'children'` | Field name of children. | | | keyboard | `boolean` | `true` | Whether the component supports keyboard operation. (Be careful about the potential conflicts with other components keyboard operations) | | | key-field | `string` | `'key'` | Field name of key. | | | label-field | `string` | `'label'` | Field name of label. | | | node-props | `(option: DropdownOption \| DropdownGroupOption) => HTMLAttributes` | `undefined` | Option HTML attributes generator. | 2.29.1 | | menu-props | `(option: DropdownOption \| undefined, options: (DropdownOption \| DropdownGroupOption)[]) => HTMLAttributes` | `undefined` | Menu HTML attributes generator. | 2.31.0 | | options | `Array` | `[]` | Dropdown options. | | | render-icon | `(option: DropdownOption) => VNodeChild` | `undefined` | Render function that renders option icons. | | | render-label | `(option: DropdownOption) => VNodeChild` | `undefined` | Render function that renders option labels. | | | render-option | `(props: { node: VNode, option: DropdownOption \| DropdownGroupOption }) => VNodeChild` | `undefined` | Render function that renders option itself. | 2.29.1 | | size | `'small'\|'medium'\|'large'\|'huge'` | `'medium'` | Dropdown size. | | | on-clickoutside | `(e: MouseEvent) => void` | `undefined` | Callback function triggered when there is a click outside of the component. | | | on-select | `(key: string \| number, option: DropdownOption) => void` | `undefined` | Callback function for after an option is selected. | | For other props, for example `placement`, please see [Popover Props](https://www.naiveui.com/en-US/components/popover.md#Popover-Props). Note that `raw` is not available. #### DropdownOption Type | Property | Type | Description | Version | | --- | --- | --- | --- | | children? | `Array` | Child options. | | | disabled? | `boolean` | Whether to disable the option. | | | icon? | `() => VNodeChild` | Custom render function of an option icon. | | | key? | `string \| number` | Option ID (should be unique). | | | label? | `string \| () => VNodeChild` | Displayed label value. | | | props? | `HTMLAttributes` | Customize option props. | | | show? | `boolean` | Whether to show the option. | 2.33.3 | #### DropdownDividerOption Type | Property | Type | Description | Version | | --- | --- | --- | --- | | key? | `string \| number` | Divider ID (should be unique). | | | show? | `boolean` | Whether to show the option. | 2.33.3 | | type | `'divider'` | The type of the DropdownDividerOption. | | #### DropdownGroupOption Type | Property | Type | Description | Version | | --- | --- | --- | --- | | children? | `Array` | Children options of DropdownGroupOption. | | | icon? | `() => VNodeChild` | Custom rendering function of the group icon. | | | label? | `string` | Group label value. | | | key? | `string \| number` | Group ID (should be unique). | | | show? | `boolean` | Whether to show the option. | 2.33.3 | | type | `'group'` | The type of the DropdownGroupOption. | | #### DropdownRenderOption Type | Property | Type | Description | Version | | --- | --- | --- | --- | | key? | `string \| number` | Render option ID (should be unique). | | | render? | `() => VNodeChild` | Render function of the option content. | | | show? | `boolean` | Whether to show the option. | 2.33.3 | | type | `'render'` | The type of the DropdownRenderOption. | | --- # Ellipsis Complexity has to live somewhere. When you hear somebody talk about a subtle concept, keep alert. ## Demos ### Basic Basic single line ellipsis with tooltip. ```vue ``` ### Line clamp See [caniuse](https://caniuse.com/?search=line-clamp) for compatibility. ```vue ``` ### Expand trigger Use `expand-trigger="click"` with the `line-clamp` parameter to achieve the function of clicking the abbreviated text to expand the complete text. ```vue ``` ### Customize tooltip content Use the `tooltip` slot to customize the tooltip content. ```vue ``` ### Better render performance In most case, normal ellipsis is fast enough. However, if you have a huge amount ellipsis to render, you may use `n-performant-ellipsis` in place of `n-ellipsis`. It has better render performance with some caveats: Inner component may be unmounted and remouted again. Use it carefully. ```vue ``` ## API ### Ellipsis, PerformantEllipsis Props `n-performant-ellipsis` since 2.35.0. | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | expand-trigger | `'click'` | `undefined` | Abbreviated content trigger event to expand to the full text. | 2.1.0 | | line-clamp | `number \| string` | `undefined` | Maximum lines. | 2.1.0 | | tooltip | `boolean \| TooltipProps` | `true` | Tooltip properties. | 2.1.0 | ### Ellipsis Slots | Name | Parameters | Description | | ------- | ---------- | ------------------------------------- | | default | `()` | The content of the ellipsis. | | tooltip | `()` | The content of the ellipsis' tooltip. | --- # Gradient Text It doesn't seem very useful... In fact it isn't. ## Demos ### Type A gradient text component can have different types. ```vue ``` ### Size `font-size` CSS also works, but can be overridden by setting the size (if just a number is used, it's taken as pixels). ```vue ``` ### Customizing gradient Design it yourself. ```vue ``` ## API ### GradientText Props | Name | Type | Default | Description | | --- | --- | --- | --- | | gradient | `string \| { from: string, to: string, deg: number \| string }` | `undefined` | Text gradient color parameters. | | size | `number \| string` | `undefined` | Text size (when the unit is not specified the default unit will be `px`). | | type | `'primary' \| 'info' \| 'success' \| 'warning' \| 'error'` | `'primary'` | Gradient Text type. | ### GradientText Slots | Name | Parameters | Description | | ------- | ---------- | --------------------------------- | | default | `()` | The content of the gradient text. | --- # Icon It is recommend to use [xicons](https://www.xicons.org) as your icon library. ## Demos ### Basic ```vue ``` ### Customize icon (Make sure SVG's viewBox attribute is set) ```vue ``` ### Depth To match different text color levels, icon provides a `depth` property. ```vue ``` ### Icon with background Sometimes it looks better with a background. ```vue ``` ## API ### Icon Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | color | `string` | `undefined` | Icon color. | | | depth | `1 \| 2 \| 3 \| 4 \| 5` | `undefined` | Icon depth. | | | size | `number \| string` | `undefined` | Icon size (when the unit is not specified the default unit is `px`). | | | component | `Component` | `undefined` | Icon component to display. | 2.24.6 | ### IconWrapper Props | Name | Type | Default | Description | Version | | ------------- | -------- | ----------- | -------------- | ------- | | border-radius | `number` | `6` | Border radius. | 2.25.0 | | color | `string` | `undefined` | Color. | 2.25.0 | | icon-color | `string` | `undefined` | Icon color. | 2.25.0 | | size | `number` | `24` | Size. | 2.25.0 | ### Icon Slots | Name | Parameters | Description | | ------- | ---------- | ------------------------ | | default | `()` | The content of the icon. | --- # PageHeader I hope this component has all the slots you need! ## Demos ### Basic ```vue ``` ## API ### PageHeader Props | Name | Type | Default | Description | | --- | --- | --- | --- | | extra | `string` | `undefined` | Extra text information. Is overwritten by the `extra` slot so only use one. | | subtitle | `string` | `undefined` | Subtitle. | | title | `string` | `undefined` | Title. | | on-back | `() => void` | `undefined` | Callback for when the back button is pressed. | ### PageHeader Slots | Name | Parameters | Description | Version | | -------- | ---------- | --------------------- | ------- | | avatar | `()` | Image information. | | | header | `()` | Header information. | | | default | `()` | Content. | | | extra | `()` | Extra information. | | | footer | `()` | Footer information. | | | subtitle | `()` | Subtitle information. | | | title | `()` | Title information. | | | back | `()` | Back icon. | 2.24.2 | --- # Tag Tags are great for showing attributes; and sometimes toggle options. ## Demos ### Type It has some types. ```vue ``` ### Borderless ```vue ``` ### Closable ```vue ``` ### Disabled ```vue ``` ### Size ```vue ``` ### Checkable It can be checkable. ```vue ``` ### Shape Round tag looks like a capsule. ```vue ``` ### Color Use a color object to customize color. ```vue ``` ### Avatar Put avatar in tag. ```vue ``` ### Icon Use icon in tag. ```vue ``` ## API ### Tag Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | bordered | `boolean` | `true` | Whether the tag has border. | | | checkable | `boolean` | `false` | Whether the tag is checkable. Note: this nullifies the type property. | | | checked | `boolean` | `false` | Whether the tag is checked. Note: used with `checkable`. | | | closable | `boolean` | `false` | Whether the tag shows a close button. | | | color | `{ color?: string, borderColor?: string, textColor?: string }` | `undefined` | Color of the tag. Note: this will override the type property's color. | | | disabled | `boolean` | `false` | Whether the tag is disabled. | | | round | `boolean` | `false` | Whether the tag has rounded corners. | | | size | `'tiny' \| 'small' \| 'medium' \| 'large'` | `'medium'` | Size of the tag. | | | strong | `boolean` | `false` | Whether to use strong text | 2.30.0 | | trigger-click-on-close | `boolean` | `false` | Whether the tag triggers click on close. | 2.32.2 | | type | `'default' \| 'primary' \| 'info' \| 'success' \| 'warning' \| 'error'` | `'default'` | Type of the tag. | | | on-close | `(e: MouseEvent) => void` | `undefined` | Close clicked callback. | | | on-update:checked | `(value: boolean) => void` | `undefined` | Checked status change callback. | | ### Tag Slots | Name | Parameters | Description | Version | | ------- | ---------- | -------------- | ------- | | avatar | `()` | Tag'a avatar. | | | default | `()` | Tag's content. | | | icon | `()` | Tag'a icon. | 2.30.0 | --- # Typography Naive UI provides some HTML text styling. Typography is an art. ## Demos ### Header Make your headers pop with a little bar to the left. Much less boring. ```vue ``` ### Tags Other naive-ui built-in tags. ```vue ``` ### Text Use different `types` to add some variety to your styles. ```vue ``` ### Use n-a with router link You can use `` for links and routes. If you think the following method is a little verbose for routes, you can always make it a new component. ```vue ``` ## API ### Text Props | Name | Type | Default | Description | | --- | --- | --- | --- | | type | `'default' \| 'success' \| 'info' \| 'warning' \| 'error'` | `'default'` | Typography type. | | strong | `boolean` | `false` | Strong. | | italic | `boolean` | `false` | Italic. | | underline | `boolean` | `false` | Underline. | | delete | `boolean` | `false` | Use the `del` tag and strikethrough style. | | code | `boolean` | `false` | Use the `code` tag and style. | | depth | `1 \| 2 \| 3 \| '1' \| '2' \| '3'` | `undefined` | Text depth (shade of text). | | tag | `string` | `undefined` | Tag to use. `code` or `delete` properties will override this. | ### P Props | Name | Type | Default | Description | | --- | --- | --- | --- | | depth | `1 \| 2 \| 3 \| '1' \| '2' \| '3'` | `undefined` | Text depth (shade of text). | ### H1, H2, H3, H4, H5, H6 Props | Name | Type | Default | Description | | --- | --- | --- | --- | | align-text | `boolean` | `false` | Text alignment. | | type | `'default' \| 'success' \| 'info' \| 'warning' \| 'error'` | `'default'` | Text color style. | | prefix | `'bar'` | `undefined` | Show a bar in front of the heading. | ### Ul, Ol Props | Name | Type | Default | Description | | ---------- | --------- | ------- | --------------- | | align-text | `boolean` | `false` | Text alignment. | ### Blockquote Props | Name | Type | Default | Description | | ---------- | --------- | ------- | --------------- | | align-text | `boolean` | `false` | Text alignment. | ### All Typography Components Slots | Name | Parameters | Description | | ------- | ---------- | -------------------------- | | default | `()` | The content of typography. | --- # Watermark Watermark. ## Demos ### Basic ```vue ``` ### Fullscreen You can make it displayed in fullscreen mode. ```vue ``` ### Image Put image here. Please note about cross origin setting of the image URL. It will influence whether the image can be displayed. ```vue ``` ### Multiline Text Supports multiple lines text separated by `\n` since `2.38.2`. Watermark supports displaying multiline text content. ```vue ``` ### Custom Watermark Preview watermark effects by configuring custom parameters. ```vue ``` ## API ### Watermark Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | content | `string` | `undefined` | Content of watermark. | 2.25.3, supports multiple line text since 2.38.2 | | cross | `boolean` | `false` | Whether to show watermark at cross position. | 2.25.3 | | debug | `boolean` | `false` | Whether to show debug grid. | 2.25.3 | | font-size | `number` | `14` | Font size. | 2.25.3 | | font-family | `string` | `undefined` | Font family. | 2.25.3 | | font-style | ``'normal' \| 'italic' \| `oblique ${number}deg` `` | `normal` | Font style. | 2.25.3 | | font-variant | `string` | `''` | Font variant. | 2.25.3 | | font-weight | `number` | `400` | Font weight. | 2.25.3 | | font-color | `string` | `rgba(128, 128, 128, .3)` | Font color. | 2.25.3 | | fullscreen | `boolean` | `false` | Whether to show fullscreen watermark. | 2.25.3 | | global-rotate | `number` | `0` | Global rotate degree of the watermark. | 2.32.0 | | line-height | `number` | `14` | Line height. | 2.25.3 | | height | `number` | `32` | Height of watermark area. | 2.25.3 | | image | `string` | `undefined` | The URI of watermark image. | 2.25.3 | | image-height | `number` | `undefined` | Image height. | 2.25.3 | | image-opacity | `number` | `1` | Image opacity. | 2.25.3 | | image-width | `number` | `undefined` | Image width. | 2.25.3 | | rotate | `number` | `0` | Rotate degree | 2.25.3 | | selectable | `boolean` | `true` | Whether content covered by watermark is selectable. | 2.25.3 | | text-align | `'left' \| 'center' \| 'right'` | `'left'` | Text align method when there's multiple lines of text. | 2.38.2 | | width | `number` | `32` | Width of watermark area. | 2.25.3 | | x-gap | `number` | `0` | Horizontal gap. | 2.25.3 | | x-offset | `number` | `0` | Horizontal offset. | 2.25.3 | | y-gap | `number` | `0` | Vertical gap. | 2.25.3 | | y-offset | `number` | `0` | Vertical offset. | 2.25.3 | | z-index | `number` | `10` | Z index of watermark. | 2.25.3 | ### Watermark Slots | Name | Parameters | Description | Version | | ------- | ---------- | ------------------------ | ------- | | default | `()` | something with watermark | 2.25.3 | --- # Float Button Like `BackTop` but with more appearance level, more interaction. Available since `2.38.0`. ## Demos ### Basic ```vue ``` ### Badge You can put a hover button with the number of badges on any element. ```vue ``` ### Tooltip ```vue ``` ### Description Show description on float button. ```vue ``` ### Float Button Group Elements can be arbitrarily combined to achieve more functionality. ```vue ``` ### Show menu After `menu-trigger` is set, more `n-float-button` can be folded into one `n-float-button`. ```vue ``` ## API ### FloatButton Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | bottom | `number \| string` | `40` | CSS `bottom` property of the button group. | 2.38.0 | | height | `number \| string` | `40` | CSS `height` property of the button group. | 2.38.0 | | left | `number \| string` | `undefined` | CSS `left` property of the button group. | 2.38.0 | | menu-trigger | `'click' \| 'hover'` | `undefined` | Trigger action to show submenu. | 2.38.0 | | position | `'relative' \| 'absolute' \| 'fixed'` | `'fixed'` | CSS `position` property of the button group. | 2.38.0 | | right | `number \| string` | `undefined` | CSS `right` property of the button group. | 2.38.0 | | shape | `'circle' \| 'square'` | `'circle'` | Shape of the button. | 2.38.0 | | show-menu | `boolean` | `undefined` | Whether submenu of the button is shown. | 2.38.0 | | top | `number \| string` | `undefined` | CSS `top` property of the button group. | 2.38.0 | | type | `'default' \| 'primary'` | `'default'` | Type of the button. | 2.38.0 | | width | `number \| string` | `undefined` | | 2.38.0 | | on-update:show-menu | `(value: boolean) => void` | `undefined` | Callback when the menu is opened or closed. | 2.38.0 | ### FloatButtonGroup Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | bottom | `number \| string` | `undefined` | CSS `bottom` property of the button group. | 2.38.0 | | left | `number \| string` | `undefined` | CSS `left` property of the button group. | 2.38.0 | | position | `'relative' \| 'absolute' \| 'fixed'` | `'fixed'` | CSS `position` property of the button group. | 2.38.0 | | right | `number \| string` | `undefined` | CSS `right` property of the button group. | 2.38.0 | | shape | `'circle' \| 'square'` | `'circle'` | Shape of the button group. | 2.38.0 | | top | `number \| string` | `undefined` | CSS `top` property of the button group. | 2.38.0 | ### FloatButton Slots | Name | Parameters | Description | Version | | ----------- | ---------- | ---------------------------- | ------- | | description | `()` | Description for the button. | 2.38.0 | | menu | `()` | Submenu of the float button. | 2.38.0 | --- # AutoComplete Offer a search hint or maybe guess some likely options? ## Demos ### Basic Start typing to see how this works. ```vue ``` ### Size ```vue ``` ### Group ```vue ``` ### Customize input element You can also replace the input element of the auto-complete component (e.g. using a textarea). ```vue ``` ### Actions after select Choose whether the element blurs after a selection is made with `blur-after-select`. ```vue ``` ### Whether to show menu Your can determine is whether to show menu based on value when it is focused. ```vue ``` ### Customized rendering Use `render-label` to customize label rendering. ```vue ``` ### Validation status Validation status can be applied outside form. ```vue ``` ### Append Append the selected option to the input box instead of directly overwriting it, and use it in conjunction with get-show. ```vue ``` ## API ### AutoComplete Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | append | `boolean` | `false` | Whether to append content to input. | 2.38.0 | | blur-after-select | `boolean` | `false` | Whether to blur after selection. | | | clear-after-select | `boolean` | `false` | Whether to clear after selection. | | | clearable | `boolean` | `false` | Whether autocomplete is clearable. | | | default-value | `string` | `null` | Default value of autocomplete. | | | disabled | `boolean` | `false` | Whether the autocomplete is disabled. | | | get-show | `(value: string) => boolean` | `undefined` | Use the input to determine whether to show options on focus. | | | input-props | `InputHTMLAttributes` | `undefined` | The attributes of input element in autocomplete. | | | loading | `boolean` | `false` | Whether to show a loading status. | | | menu-props | `HTMLAttributes` | `undefined` | The menu's dom props. | 2.32.2 | | options | `Array` | `[]` | Options to autocomplete from. | | | placeholder | `string` | `'Please Input'` | Autocomplete's placeholder. | | | placement | `'top-start' \| 'top' \| 'top-end' \| 'right-start' \| 'right' \| 'right-end' \| 'bottom-start' \| 'bottom' \| 'bottom-end' \| 'left-start' \| 'left' \| 'left-end'` | `'bottom-start'` | Autocomplete's placement. | 2.25.0 | | render-label | `(option: SelectOption \| SelectGroupOption, selected: boolean) => VNodeChild` | `undefined` | Render function for each option label. | 2.24.0 | | render-option | `(info: { node: VNode, option: SelectOption \| SelectGroupOption, selected: boolean }) => VNodeChild` | `undefined` | Render function for each option. | 2.24.0 | | scrollbar-props | `ScrollbarProps` | `undefined` | See [Scrollbar props](https://www.naiveui.com/en-US/components/scrollbar.md#Scrollbar-Props) | 2.44.0 | | show-empty | `boolean` | `false` | Whether to show menu if there's no option. | 2.37.1 | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | Autocomplete size. | | | status | `'success' \| 'warning' \| 'error'` | `undefined` | Validation status. | 2.27.0 | | to | `string \| HTMLElement \| false` | `body` | Container node of the menu. `false` will keep it not detached. | | | value | `string` | `undefined` | Input of autocomplete. | | | on-blur | `(event: FocusEvent) => void` | `undefined` | On blur callback function. | | | on-focus | `(event: FocusEvent) => void` | `undefined` | On focus callback function. | | | on-select | `(value: string) => void` | `undefined` | On select callback function. | | | on-update:value | `(value: string \| null) => void` | `undefined` | On update callback function. | | #### AutoCompleteOption Properties | Name | Type | Description | | -------- | --------- | ------------------------------- | | disabled | `boolean` | Whether the option is disabled. | | label | `string` | Option label value. | | value | `string` | Option ID (should be unique). | #### AutoCompleteGroupOption Properties | Name | Type | Description | | -------- | ------------------------------------- | ----------------------- | | children | `Array` | Group children options. | | label | `string` | Group label. | | key | `string \| number` | Unique group key. | | type | `'group'` | Required group type. | ### AutoComplete Slots | Name | Parameters | Description | Version | | --- | --- | --- | --- | | default | `(options: { handleInput: (value: string) => void, handleFocus: function, handleBlur: function, value: string, theme: string \| null })` | Custom input elements, supplied by the user. | | | empty | `()` | Menu's content to show when there's no option. | 2.37.1 | | prefix | `()` | Input's prefix content. | | | suffix | `()` | Input's suffix content. | | ### AutoComplete Methods | Name | Type | Description | Version | | ----- | ------------ | ------------------------ | ------- | | blur | `() => void` | Blur the input element. | 2.26.2 | | focus | `() => void` | Focus the input element. | 2.26.2 | --- # Cascader Cascader can be used to display and select tree structured data. ## Demos ### Single ```vue ``` ### Multiple ```vue ``` ### Size Cascader has `small`, `medium` and `large` sizes. ```vue ``` ### Single (async) ```vue ``` ### Multiple (async) ```vue ``` ### Slots Is there anybody who needs slots on a cascader menu? ```vue ``` ### Large data In this example there are 5000 \* 2 \* 2 = 20000 entries. ```vue ``` ### Setting check strategy Set the way to show checked options. `all` means showing all checked nodes. `parent` means showing all checked parent nodes when all child node are checked. `child` means showing all child nodes. ```vue ``` ### Customizing Fields Various data would come from backend. ```vue ``` ### Customized rendering The `render-label` can be used to batch render cascader menu options. ```vue ``` ### Focus & blur manually ```vue ``` ### Validation status Validation status can be applied outside form. ```vue ``` ## API ### Cascader Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | allow-checking-not-loaded | `boolean` | `false` | Whether to allow cascade checking on not loaded nodes. If you want to use this, you should know the `value` may be incomplete. Also, you should aware about the consistency bewteen naive's checking logic and your backend's checking logic, especially when there are disabled nodes. | 2.28.1 | | cascade | `boolean` | `true` | Whether to cascade the checkbox selection onto children. | | | check-strategy | `string` | `'all'` | The way to show checked options. `all` means showing all checked node. `parent` means showing all checked parent node when all child node are checked (not working in single select mode). `child` means showing all child node. | | | children-field | `string` | `'children'` | The children field in `CascaderOption`. | | | clearable | `boolean` | `false` | Whether the cascader is clearable. | | | clear-filter-after-select | `boolean` | `true` | When multiple and filter is true, whether to clear filter keyword after select an option. | 2.25.3 | | default-value | `string \| number \| Array \| null` | `null` | Data selected by default if no value is set. | | | disabled | `boolean` | `false` | Whether to disable the cascader. | | | disabled-field | `string` | `'disabled'` | The disabled field in `CascaderOption`. | 2.32.2 | | ellipsis-tag-popover-props | `PopoverProps` | `undefined` | `popover` props of the preview ellipsis tag. | 2.37.0 | | expand-trigger | `'click' \| 'hover'` | `'click'` | If `remote` is set, `'hover'` won't work. | | | filterable | `boolean` | `false` | Note: If `remote` is set, this won't have any effect. | | | filter | `(pattern: string, option: CascaderOption, path: CascaderOption[]) => boolean` | A string based filter algorithm. | Filter function of the cascader. | | | filter-menu-props | `HTMLAttributes` | `undefined` | The filter menu's dom props. | 2.27.0 | | get-column-style | `(detail: { level: number }) => string \| object` | `undefined` | Function that resolves column style. `level` starts from `0`. | 2.38.2 | | value-field | `string` | `'value'` | The value field in `CascaderOption`. | | | label-field | `string` | `'label'` | The label field in `CascaderOption`. | | | max-tag-count | `number \| 'responsive'` | `undefined` | Max tag count in multiple select mode. `responsive` will keep all the tags in single line. | | | menu-props | `HTMLAttributes` | `undefined` | The menu's dom props. | 2.27.0 | | multiple | `boolean` | `false` | Whether to allow multiple options being selected. | | | options | `CascaderOption[]` | `[]` | Options of the cascader. | | | placeholder | `string` | `'Please Select'` | Placeholder text. | | | placement | `'top-start' \| 'top' \| 'top-end' \| 'right-start' \| 'right' \| 'right-end' \| 'bottom-start' \| 'bottom' \| 'bottom-end' \| 'left-start' \| 'left' \| 'left-end'` | `'bottom-start'` | Cascader placement. | 2.25.0 | | remote | `boolean` | `false` | Whether to obtain data remotely. | | | render-prefix | `(info: { option: CascaderOption, node: VNode \| null, checked: boolean }) => VNodeChild` | `undefined` | Render function of all the options' prefix. | 2.38.2 | | render-label | `(option: CascaderOption, checked: boolean) => VNodeChild` | `undefined` | Render function for cascader menu option label. | 2.24.0 | | render-suffix | `(info: { option: CascaderOption, node: VNode \| null, checked: boolean }) => VNodeChild` | `undefined` | Render function of all the options' suffix. | 2.38.2 | | scrollbar-props | `ScrollbarProps` | `undefined` | See [Scrollbar props](https://www.naiveui.com/en-US/components/scrollbar.md#Scrollbar-Props) | 2.44.0 | | separator | `string` | `' / '` | Selected option path value separator (used with `show-path`). | | | show | `boolean` | `undefined` | Whether to show the menu. | | | show-path | `boolean` | `true` | Whether to show the selected options as a path. | | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | Cascader size. | | | spin-props | `{ strokeWidth?: number, stroke?: string, scale?: number, radius?: number }` | `undefined` | Loading icon properties. | 2.44.0 | | status | `'success' \| 'warning' \| 'error'` | `undefined` | Validation status. | 2.27.0 | | to | `string \| HTMLElement \| false` | `body` | Container node of the menu. `false` will keep it not detached. | | | value | `string \| number \| Array \| null` | `undefined` | Value of the cascader (if being set manually). | | | virtual-scroll | `boolean` | `true` | Whether to enable virtual scrolling. | | | on-blur | `() => void` | `undefined` | Callback on blurred. | | | on-focus | `() => void` | `undefined` | Callback on focused. | | | on-load | `(option: CascaderOption) => Promise` | `undefined` | Callback when a node is loaded. Set `option.children` in the returned promise. Loading will stop after the promise is resolved or rejected. | | | on-update:show | `(value: boolean) => void` | `undefined` | Callback executed when menu is opened & closed. | | | on-update:value | `(value: string \| number \| Array \| null, option: CascaderOption \| Array \| null, pathValues: Array \| Array \| null) => void` | `undefined` | Callback executed when the value changes. | | #### CascaderOption Properties | Name | Type | Description | Version | | --- | --- | --- | --- | | label | `string` | Label of the option. | | | value | `string \| number` | Value of the option. | | | disabled? | `boolean` | Whether this option is disabled. | | | children? | `CascaderOption` | The children options of this option. | | ### Cascader Slots | Name | Parameters | Description | Version | | --- | --- | --- | --- | | action | `()` | Action content displayed in the cascading menu. | | | arrow | `()` | Arrow content displayed in the cascading menu. | 2.32.2 | | empty | `()` | Empty state slot for the options cascading menu. | 2.22.0 | | not-found | `()` | Data not found slot when searching. | 2.34.0 | ### Cascader Methods | Name | Type | Description | Version | | --- | --- | --- | --- | | blur | `() => void` | Blur. | 2.24.2 | | focus | `() => void` | Focus. | 2.24.2 | | getCheckedData | `() => { keys: Array, options: Array }` | Get checked data. | 2.34.0 | | getIndeterminateData | `() => { keys: Array, options: Array }` | Get indeterminate data. | 2.34.0 | --- # Color Picker Unlike the real world, these color values are discrete. ## Demos ### Basic A basic color picker. Note: when choosing a color in a particular mode, that's the mode that will be used. ```vue ``` ### Alpha Use `show-alpha` to control whether the alpha channel can be adjusted. ```vue ``` ### Size `small`, `medium`, `large`. ```vue ``` ### Disabled ```vue ``` ### Set mode Use `modes` to set restrict the available modes. ```vue ``` ### Clearable If you want the color picker to be clearable, you can add `'clear'` in `'actions'` prop. ```vue ``` ### Use with form It seems this example is useless, but it's a data input component so I just left it here. ```vue ``` ### Swatches Set color swatches for users to choose. ```vue ``` ### Custom Trigger Use the `trigger` slot to customize the trigger. ```vue ``` ### Native We provide a way to trigger the browser's native color selector by clicking on the color preview block, because browser manufacturers have implemented some great features on the native color selector, which you may need. ```vue ``` ## API ### ColorPicker Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | default-show | `boolean` | `undefined` | Whether to show the color panel by default. | | | default-value | `string` | Black color value of 1st mode's corresponding value. | Default value of the picker. | | | modes | `Array<'rgb' \| 'hex' \| 'hsl' \| 'hsv'>` | `['rgb', 'hex', 'hsl']` | The value format of the picker. Notice that value will follow the mode once you select a new value from the picker. | | | placement | `'top-start' \| 'top' \| 'top-end' \| 'right-start' \| 'right' \| 'right-end' \| 'bottom-start' \| 'bottom' \| 'bottom-end' \| 'left-start' \| 'left' \| 'left-end'` | `'bottom-start'` | Color panel placement. | 2.25.0 | | render-label | `(color: string \| null) => VNodeChild` | `undefined` | Label render function of the color picker trigger. | 2.24.0 | | show | `boolean` | `undefined` | Whether the color panel is shown. | | | show-alpha | `boolean` | `true` | Whether the alpha channel can be adjusted. | | | show-preview | `boolean` | `false` | Whether the color preview is shown. | | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | Size of the picker. | | | disabled | `boolean` | `false` | Whether to disable the color picker. | 2.24.5 | | swatches | `string[]` | `undefined` | Value of the swatches. | | | to | `string \| HTMLElement \| false` | `'body'` | Where to attach the panel to. `false` will keep it not detached. | | | value | `string \| null` | `undefined` | Value of the picker. | | | on-complete | `(value: string) => void` | `undefined` | Callback once the value is changed completely (not called during mousemove). | | | on-confirm | `(value: string) => void` | `undefined` | Callback once the confirm button is clicked. | 2.29.0 | | on-clear | `() => void` | `undefined` | Callback once the clear button is clicked. | 2.39.0 | | on-update:show | `(value: boolean) => void` | `undefined` | Callback once panel the show status is changed. | | | on-update:value | `(value: string) => void` | `undefined` | Callback once the value is changed. | | | actions | `Array<'confirm' \| 'clear'> \| null` | `null` | The types of buttons to be shown in the panel. | | ### ColorPicker Slots | Name | Parameters | Description | Version | | --- | --- | --- | --- | | action | `()` | Custom action. | 2.24.0 | | label | `(color: string \| null)` | Label of the color picker trigger. | 2.24.0 | | trigger | `(props: { value: string \| null , onClick: (() => void) \| undefined, ref: (ref: Element \| ComponentPublicInstance \| null }) => void })` | Custom trigger element. Only one element is allowed & it can't be pure text. | 2.44.0 | ## Q & A ### How to get color value from name? Naive doesn't provide it builtin. You can create a color map, like [https://github.com/bgrins/TinyColor/blob/master/tinycolor.js#L803](https://github.com/bgrins/TinyColor/blob/master/tinycolor.js#L803). Or you can create a function like this. ```js export function getRgb(colorName) { const el = document.createElement('div') el.style.color = colorName document.body.appendChild(el) const rgbColor = getComputedStyle(el).color document.body.removeChild(el) return rgbColor } ``` --- # Checkbox Yo, yo, check it out. ## Demos ### Basic ```vue ``` ### Size ```vue ``` ### Checkbox group ```vue ``` ### Using Options Pass option data directly through the `options` prop. You can also customize field names with `label-field` and `value-field`. ```vue ``` ### Grid Use checkboxes with a grid. ```vue ``` ### Indeterminate ```vue ``` ### Controlled checkbox ```vue ``` ### Event ```vue ``` ### Customizing checked value Use `checked-value` and `unchecked-value` to customize value. ```vue ``` ### Focus & blur manually ```vue ``` ## API ### Checkbox Props | Name | Type | Default | Description | | --- | --- | --- | --- | | checked | `boolean` | `false` | Whether the checkbox is being checked manually. | | checked-value | `string \| boolean \| number` | `true` | Value of checked state. | | default-checked | `boolean` | `false` | Whether the checkbox is checked by default. | | disabled | `boolean` | `false` | Whether the checkbox is disabled. | | focusable | `boolean` | `true` | Whether the checkbox gains focus after being checked. | | indeterminate | `boolean` | `false` | Whether the checkbox can have a third indeterminate state. | | label | `string` | `undefined` | Checkbox label. | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | The size of the checkbox. | | unchecked-value | `string \| boolean \| number` | `false` | Value of unchecked state. | | value | `string \| number` | `undefined` | The value of the checkbox to be used in a checkbox group. | | on-update:checked | `(checked: boolean) => void` | `undefined` | Callback function triggered on a checked status change. | ### CheckboxGroup Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | disabled | `boolean` | `false` | Whether the checkbox group is disabled. | | | default-value | `Array` | `null` | Checkbox group's default selected value. | | | label-field | `string` | `'label'` | The field name of option labels in `options`. | 2.45.0 | | max | `number` | `undefined` | The maximum number of checkboxes that can be checked. | | | min | `number` | `undefined` | The minimum number of checkboxes that can be checked. | | | options | `Array<{ label?: string, value: string \| number, disabled?: boolean }>` | `undefined` | Options for the checkbox group. When set, the default slot is ignored. | 2.45.0 | | value | `Array \| null` | `undefined` | Manually set values of a checkbox group. | | | value-field | `string` | `'value'` | The field name of option values in `options`. | 2.45.0 | | on-update:value | `(value: (string \| number)[], meta: { actionType: 'check' \| 'uncheck', value: string \| number }) => void` | `undefined` | Callback when the checkbox group's value changes. | `meta` 2.32.0 | ### Checkbox Slots | Name | Parameters | Description | | ------- | ---------- | ------------------------ | | default | `()` | Content of the checkbox. | ### CheckboxGroup Slots | Name | Parameters | Description | | ------- | ---------- | ------------------------------ | | default | `()` | Content of the checkbox group. | ### Checkbox Methods | Name | Type | Description | Version | | ----- | ------------ | ----------- | ------- | | focus | `() => void` | Focus. | 2.24.2 | | blur | `() => void` | Blur. | 2.24.2 | --- # Date Picker People have too many ideas on how to set the time. ## Demos ### Date ```vue ``` ### Date time ```vue ``` ### Formatted value Honestly I don't like the feature. Since at most of time it's not a best practice to passing time string around. However, real world is complex, I hope it can help you resolve some tricky problems. ```vue ``` ### Date range ```vue ``` ### Date time range ```vue ``` ### Month Use `month-format` to format month item inside panel. ```vue ``` ### Month range ```vue ``` ### Year ```vue ``` ### Year range ```vue ``` ### Quarter ```vue ``` ### Quarter range ```vue ``` ### Week ```vue ``` ### Size Date Picker can be `small`, `medium` or `large` sized. ```vue ``` ### Default time You can set the default time of picked date. ```vue ``` ### Disabled ```vue ``` ### Disabled specific time ```vue ``` ### Actions ```vue ``` ### Shortcuts You can customize some shorcut buttons. ```vue ``` ### Events ```vue ``` ### Format ```vue ``` ### Extra footer ```vue ``` ### Update value on close ```vue ``` ### Focus & blur manually ```vue ``` ### Validation status Validation status can be applied outside form. ```vue ``` ### Icon ```vue ``` ### Use panel only It may be useful sometimes. ```vue ``` ### Close panel on select year or month By using the `fast-year-select` and `fast-month-select` properties, you can implement the closing of the year and month panel after selecting the year or month. ```vue ``` ## API ### General Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | calendar-day-format | `string` | `undefined` | Weekday format inside popup panel. | 2.40.2 | | calendar-header-year-format | `string` | `undefined` | Year format inside the header of popup panel's calendar. | 2.40.2 | | calendar-header-month-format | `string` | `undefined` | Month format inside the header of popup panel's calendar. | 2.40.2 | | calendar-header-month-before-year | `string` | `undefined` | Whether to show month before year inside the header of popup panel's calender. | 2.40.2 | | calendar-header-month-year-separator | `string` | `' '` | Separator between month and year inside the header of popup panel's calendar. | 2.40.2 | | clearable | `boolean` | `false` | Whether the date picker is clearable. | | | date-format | `string` | `undefined` | Date input format inside popup panel. | 2.40.2 | | default-value | `number \| [number, number] \| null` | `undefined` | Date picker's default value. | | | default-formatted-value | `string \| [string, string] \| null` | `undefined` | Date picker's default formatted value. | 2.24.0 | | disabled | `boolean` | `false` | Whether the date picker is disabled. | | | first-day-of-week | `0 \| 1 \| 2 \| 3 \| 4 \| 5 \| 6` | `undefined` | The first day of a week on calendar, 0 means Monday. | | | input-readonly | `boolean` | `false` | Set the `readonly` attribute of the input (avoids virtual keyboard on touch devices). | | | month-format | `string` | `'M'` | Format of month item in the panel. See [format](https://date-fns.org/v2.23.0/docs/format). | 2.37.0 | | panel | `boolean` | `false` | Whether to use date-picker as panel. | 2.29.1 | | placement | `'top-start' \| 'top' \| 'top-end' \| 'right-start' \| 'right' \| 'right-end' \| 'bottom-start' \| 'bottom' \| 'bottom-end' \| 'left-start' \| 'left' \| 'left-end'` | `'bottom-start'` | Panel's placement. | 2.25.0 | | quarter-format | `string` | `'Q'Q` | Format of quarter item in the panel. See [format](https://date-fns.org/v2.23.0/docs/format). | 2.37.0 | | shortcuts | `Record number)> \| Record [number, number])>` | `undefined` | Shortcut button customizations. | | | show | `boolean` | `undefined` | Whether to show panel. | 2.28.3 | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | Date picker size. | | | status | `'success' \| 'warning' \| 'error'` | `undefined` | Validation status. | 2.27.0 | | time-picker-format | `string \| undefined` | `undefined` | Format of the binding value in time picker inside date picker of type `'datetime'` and `'datetimerange'`. See [format](https://date-fns.org/v2.23.0/docs/format). | 2.38.2 | | to | `string \| HTMLElement \| false` | `body` | Container node of the panel. `false` will keep it not detached. | | | type | `'date' \| 'datetime' \| 'daterange' \| 'datetimerange' \| 'month' \| 'monthrange' \| 'year' \| 'yearrange' \| 'quarter' \| 'quarterrange' \| 'week'` | `'date'` | Date picker type. | `'quarter'` v2.22.0, `'monthrange'` 2.28.3 | | value | `number \| [number, number] \| null` | `undefined` | Value of the date picker when being manually set. | | | value-format | `string` | Follow `format` prop | Format of the binding value. See [format](https://date-fns.org/v2.23.0/docs/format). | 2.24.0 | | year-format | `string` | `'y'` | Format of year item in the panel. See [format](https://date-fns.org/v2.23.0/docs/format). | 2.37.0 | | year-range | `[number, number]` | `[1901, 2100]` | Year range in month picker in panel. | 2.40.0 | | on-clear | `() => void` | `undefined` | On clear callback. | 2.28.3 | | on-confirm | `(value: number \| [number, number] \| null, formattedValue: string \| [string, string] \| null) => void` | `undefined` | On confirm callback. | 2.28.3 | | on-blur | `() => void` | `undefined` | On blur callback. | | | on-focus | `() => void` | `undefined` | On focus callback. | | | on-next-month | `() => void` | `undefined` | Callback when click next month button. | 2.37.0 | | on-next-year | `() => void` | `undefined` | Callback when click next year button. | 2.37.0 | | on-prev-month | `() => void` | `undefined` | Callback when click previous month button. | 2.37.0 | | on-prev-year | `() => void` | `undefined` | Callback when click previous year button. | 2.37.0 | | on-update:show | `(show: boolean) => void` | `undefined` | Callback when panel shows & hides. | 2.28.3 | ### Date Type Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | actions | `Array<'clear' \| 'now'> \| null` | `['clear', 'now']` | Operations supported for the `date` type date picker. | | | default-calendar-start-time | `number` | `undefined` | Default panel calendar start month timestamp. | 2.38.1 | | fast-year-select | `boolean` | `false` | Close year and month panel after selecting year. | 2.44.0 | | fast-month-select | `boolean` | `false` | Close year and month panel after selecting month. | 2.44.0 | | format | `string` | `'yyyy-MM-dd'` | Format of the input. For detail please see [format](https://date-fns.org/v2.23.0/docs/format). | | | is-date-disabled | `(current: number, detail: { type: 'date', year: number, month: number, date: number } \| { type: 'month', year: number, month: number } \| { type: 'year', year: number } \| { type: 'quarter', year: number, quarter: number } \| { type: 'input' }) => boolean` | `() => false` | Validator of the date. | `detail` 2.37.1 | | placeholder | `string` | `'Select Date'` | Placeholder. | | | on-update:formatted-value | `(value: string \| null, timestampValue: number \| null) => void` | `undefined` | Date selected callback. | 2.24.0 | | on-update:value | `(value: number \| null, formattedValue: string \| null) => void` | `undefined` | Date selected callback. | `formattedValue` 2.24.0 | ### DateTime Type Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | actions | `Array<'clear' \| 'now' \| 'confirm'> \| null` | `['clear', 'now', 'confirm']` | Operations supported for the `datetime` type date picker. | | | default-calendar-start-time | `number` | `undefined` | Default panel calendar start month timestamp. | 2.38.1 | | default-time | `string \| (timestamp: number) => string` | `undefined` | Default time of the selected date. Can accept a function with a timestamp argument that returns a formatted string. It's format is `HH:mm:ss`. | 2.22.0, functional since 2.43.2 | | fast-year-select | `boolean` | `false` | Close year and month panel after selecting year. | 2.44.0 | | fast-month-select | `boolean` | `false` | Close year and month panel after selecting month. | 2.44.0 | | format | `string` | `'yyyy-MM-dd HH:mm:ss'` | Format of the input. For detail please see [format](https://date-fns.org/v2.23.0/docs/format). | | | is-date-disabled | `(current: number, detail: { type: 'date', year: number, month: number, date: number } \| { type: 'month', year: number, month: number } \| { type: 'year', year: number } \| { type: 'quarter', year: number, quarter: number } \| { type: 'input' }) => boolean` | `() => false` | Validator of the date. | `detail` 2.37.1 | | is-time-disabled | `(current: number) => { isHourDisabled?: () => boolean, isMinuteDisabled?: () => boolean, isSecondDisabled?: () => boolean }` | `undefined` | Validator of the time. | | | placeholder | `string` | `'Select Date and Time'` | Placeholder. | | | time-picker-props | `TimePickerProps` | `undefined` | Time picker props in the panel. | 2.27.0 | | update-value-on-close | `boolean` | `false` | Whether to update value on close. | | | on-update:formatted-value | `(value: string \| null, timestampValue: number \| null) => void` | `undefined` | Date selected callback. | MEXT_VERSION | | on-update:value | `(value: number \| null, formattedValue: string \| null) => void` | `undefined` | Date selected callback. | `formattedValue` 2.24.0 | ### DateRange Type Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | actions | `Array<'clear' \| 'confirm'> \| null` | `['clear', 'confirm']` | Operations supported for the `daterange` type date picker. | | | bind-calendar-months | `boolean` | `false` | Whether months in panel calendar are consecutive. | 2.28.3 | | default-calendar-start-time | `number` | `undefined` | Default panel calendar start month timestamp. | 2.28.3 | | default-calendar-end-time | `number` | `undefined` | Default panel calendar end month timestamp. | 2.28.3 | | end-placeholder | `string` | `'End Date'` | Placeholder at end part of the input. | | | fast-year-select | `boolean` | `false` | Close year and month panel after selecting year. | 2.44.0 | | fast-month-select | `boolean` | `false` | Close year and month panel after selecting month. | 2.44.0 | | format | `string` | `'yyyy-MM-dd'` | Format of the input. For detail please see [format](https://date-fns.org/v2.23.0/docs/format). | | | is-date-disabled | `(current: number, phase: 'start' \| 'end', value: [number, number] \| null) => boolean` | `undefined` | Validator of the date. | `detail` 2.37.1 | | is-time-disabled | `(current: number, phase: 'start' \| 'end', value: [number, number]) => { isHourDisabled?: (hour: number) => boolean, isMinuteDisabled?: (minute: number, hour: number \| null) => boolean, isSecondDisabled?: (second: number, minute: number \| null, hour: number \| null) => boolean }` | `undefined` | Validator of the time. `null` in validators means value of picker is empty. | | | close-on-select | `boolean` | `false` | Whether to close the panel after the user has selected a time range. | | | separator | `string` | internal icon | The separator between the start input and the end input. | | | start-placeholder | `string` | `'Start Date'` | The prompt information at the beginning of the input. | | | update-value-on-close | `boolean` | `false` | Whether to update the value on close. | | | on-update:formatted-value | `(value: [string, string] \| null, timestampValue: [number, number] \| null) => void` | `undefined` | Formatted range changed callback. | 2.24.0 | | on-update:value | `(value: [number, number] \| null, formattedValue: [string, string] \| null) => void` | `undefined` | Range changed callback. | `formattedValue` 2.24.0 | ### DateTimeRange Type Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | actions | `Array<'clear' \| 'confirm'> \| null` | `['clear', 'confirm']` | Operations supported for the `datetimerange` type. | | | bind-calendar-months | `boolean` | `false` | Whether months in panel calendar are consecutive. | 2.28.3 | | default-calendar-start-time | `number` | `undefined` | Default panel calendar start month timestamp. | 2.28.3 | | default-calendar-end-time | `number` | `undefined` | Default panel calendar end month timestamp. | 2.28.3 | | default-time | `string \| Array \| (timestamp: number, position: "start" \| "end", value: [number, number] \| null) => string` | `undefined` | Default time of the selected date. Can accept a function with timestamp, position and value arguments that returns a formatted string. It's format is `HH:mm:ss`. | 2.22.0, functional since 2.43.2 | | end-placeholder | `string` | `'End Date and Time'` | Placeholder at end part of the input. | | | fast-year-select | `boolean` | `false` | Close year and month panel after selecting year. | 2.44.0 | | fast-month-select | `boolean` | `false` | Close year and month panel after selecting month. | 2.44.0 | | format | `string` | `'yyyy-MM-dd HH:mm:ss'` | Format of the input. For detail please see [format](https://date-fns.org/v2.23.0/docs/format). | | | is-date-disabled | `(current: number, phase: 'start' \| 'end', value: [number, number] \| null) => boolean` | `undefined` | Validator of the date. | | | is-time-disabled | `(current: number, phase: 'start' \| 'end', value: [number, number]) => { isHourDisabled?: (hour: number) => boolean, isMinuteDisabled?: (minute: number, hour: number \| null) => boolean, isSecondDisabled?: (second: number, minute: number \| null, hour: number \| null) => boolean }` | `undefined` | Validator of the time. `null` in validators means value of picker is empty. | | | separator | `string` | internal icon | The separator between the start input and the end input. | | | start-placeholder | `string` | `'Start Date and Time'` | The prompt information at the beginning of the input. | | | time-picker-props | `TimePickerProps \| [TimePickerProps, TimePickerProps]` | `undefined` | Time picker props in the panel. | 2.27.0 | | update-value-on-close | `boolean` | `false` | Whether to update value on close. | | | on-update:formatted-value | `(value: [string, string] \| null, timestampValue: [number, number] \| null) => void` | `undefined` | Formatted value changed callback. | 2.24.0 | | on-update:value | `(value: [number, number] \| null, formattedValue: [string, string] \| null) => void` | `undefined` | Value changed callback. | `formattedValue` 2.24.0 | ### Month Type Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | actions | `Array<'clear' \| 'now' \| 'confirm'> \| null` | `['clear', 'now']` | Operations supported for the `month` type date picker. | | | format | `string` | `'yyyy-MM'` | Format of the input. For detail please see [format](https://date-fns.org/v2.23.0/docs/format). | | | is-date-disabled | `(current: number, detail: { type: 'date', year: number, month: number, date: number } \| { type: 'month', year: number, month: number } \| { type: 'year', year: number } \| { type: 'quarter', year: number, quarter: number } \| { type: 'input' }) => boolean` | `() => false` | Validator of the month. | `detail` 2.37.1 | | placeholder | `string` | `'Select Month'` | Placeholder. | | | on-update:formatted-value | `(value: string \| null, timestampValue: number \| null) => void` | `undefined` | Formatted value changed callback. | 2.24.0 | | on-update:value | `(value: number \| null, formattedValue: string \| null) => void` | `undefined` | Value changed callback. | `formattedValue` 2.24.0 | ### MonthRange, QuarterRange, YearRange Type Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | actions | `Array<'clear' \| 'confirm'> \| null` | `['clear', 'confirm']` | Operations supported for the `monthrange` type date picker. | 2.28.3 | | end-placeholder | `string` | `'End Month'` | Placeholder at end part of the input. | 2.28.3 | | format | `string` | `'yyyy-MM-dd'` | Format of the input. For detail please see [format](https://date-fns.org/v2.23.0/docs/format). | 2.28.3 | | close-on-select | `boolean` | `false` | Whether to close the panel after the user has selected a time range. | 2.28.3 | | separator | `string` | internal icon | The separator between the start input and the end input. | 2.28.3 | | start-placeholder | `string` | `'Start Month'` | The prompt information at the beginning of the input. | 2.28.3 | | update-value-on-close | `boolean` | `false` | Whether to update the value on close. | 2.28.3 | | on-update:formatted-value | `(value: [string, string] \| null, timestampValue: [number, number] \| null) => void` | `undefined` | Formatted range changed callback. | 2.28.3 | | on-update:value | `(value: [number, number] \| null, formattedValue: [string, string] \| null) => void` | `undefined` | Range changed callback. | 2.28.3 | ### Year Type Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | actions | `Array<'clear' \| 'now'> \| null` | `['clear', 'now']` | Operations supported for the `year` type date picker. | | | format | `string` | `'yyyy'` | Format of the input. For detail please see [format](https://date-fns.org/v2.23.0/docs/format). | | | is-date-disabled | `(current: number, detail: { type: 'date', year: number, month: number, date: number } \| { type: 'month', year: number, month: number } \| { type: 'year', year: number } \| { type: 'quarter', year: number, quarter: number } \| { type: 'input' }) => boolean` | `() => false` | Validator of the year. | `detail` 2.37.1 | | placeholder | `string` | `'Select Year'` | Placeholder. | | | on-update:formatted-value | `(value: string \| null, timestampValue: number \| null) => void` | `undefined` | Formatted value changed callback. | 2.24.0 | | on-update:value | `(value: number \| null, formattedValue: string \| null) => void` | `undefined` | Value changed callback. | `formattedValue` 2.24.0 | ### Week Type Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | actions | `Array<'clear' \| 'now'> \| null` | `['clear', 'now']` | Operations supported for the `week` type date picker. | 2.37.0 | | default-calendar-start-time | `number` | `undefined` | Default panel calendar start month timestamp. | 2.38.1 | | format | `string` | `'YYYY-w'` for en-US, Locale specific. | Format of the input. For detail please see [format](https://date-fns.org/v2.23.0/docs/format). | 2.37.0 | | placeholder | `string` | `'Select Week'` for en-US, Locale specific. | Placeholder. | 2.37.0 | | on-update:formatted-value | `(value: string \| null, timestampValue: number \| null) => void` | `undefined` | Formatted value changed callback. | 2.37.0 | | on-update:value | `(value: number \| null, formattedValue: string \| null) => void` | `undefined` | Value changed callback. | 2.37.0 | ### DatePicker Slots | Name | Parameters | Description | Version | | ---------- | ---------- | --------------------------------- | ------- | | date-icon | `()` | Date icon of the input box. | 2.29.0 | | footer | `()` | Extra Footer. | | | next-month | `()` | Next icon of the date panel. | 2.33.4 | | next-year | `()` | Fast next icon of the date panel. | 2.33.4 | | prev-month | `()` | Prev icon of the date panel. | 2.33.4 | | prev-year | `()` | Fast prev icon of the date panel. | 2.33.4 | | separator | `()` | Separator of range picker. | 2.29.0 | ### Date, Year, QuarterRange, Week Slots | 名称 | 参数 | 说明 | 版本 | | --- | --- | --- | --- | | clear | `(props: { onClear: () => void, text: string })` | Clear button of the panel. | 2.40.0 | | now | `(props: { onNow: () => void, text: string })` | Now button of the panel. | 2.40.0 | ### DateRange, DateTimeRange, MonthRange, YearRange Slots | 名称 | 参数 | 说明 | 版本 | | --- | --- | --- | --- | | clear | `(props: { onClear: () => void, text: string })` | Clear button of the panel. | 2.40.0 | | confirm | `(props: { onConfirm: () => void, disabled: boolean, text: string })` | Confirm button of the panel. | 2.40.0 | ### DateTime, Month, Quarter Slots | 名称 | 参数 | 说明 | 版本 | | --- | --- | --- | --- | | clear | `(props: { onClear: () => void, text: string })` | Clear button of the panel. | 2.40.0 | | confirm | `(props: { onConfirm: () => void, disabled: boolean, text: string })` | Confirm button of the panel. | 2.40.0 | | now | `(props: { onNow: () => void, text: string })` | Now button of the panel. | 2.40.0 | ### DatePicker Methods | Name | Type | Description | Version | | ----- | ------------ | ----------- | ------- | | focus | `() => void` | Focus. | 2.24.2 | | blur | `() => void` | Blur. | 2.24.2 | --- # Dynamic Input This component's name has been changed so many times. In the beginning, it was created for entering environment variables. If you find the component doesn't look like what you want, I recommend you to write a new one. It's probably easier than using this one. ## Demos ### Use input preset By default, the preset element of `n-dynamic-input` is `input`. ```vue ``` ### Using pair preset ```vue ``` ### Customizing input content ```vue ``` ### Using it in a form `n-dynamic-input` itself cannot be verified. If you need to verify the input of `n-dynamic-input`, you can pass `n-form-item` in the custom content to complete the verification. Here is a complete example. ```vue ``` ### Show sort button ```vue ``` ### Customizing action ```vue ``` ## API ### DynamicInput Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | create-button-props | `ButtonProps` | `undefined` | Props of create item button. | 2.25.0 | | default-value | `unknown[]` | `[]` | Default value. | | | disabled | `boolean` | `false` | Whether to disable the dynamic-input. It won't work for custom content. | 2.34.4 | | item-class | `string` | `undefined` | The class of each item of the dynamic input. | 2.36.0 | | item-style | `string \| Object` | `undefined` | The style of each item of the dynamic input. | | | key-field | `string` | `undefined` | The key of each item that should be used in the rendering of the list. | | | min | `number` | `0` | Minimum number of items. | | | max | `number` | `undefined` | Maximum number of items. | | | preset | `'input' \| 'pair'` | `'input'` | The preset of `n-dynamic-input`, it work when `$slots.default` is not set. | | | show-sort-button | `boolean` | `false` | Whether to show sort button. | 2.25.0 | | value | `unknown[]` | `undefined` | Value in controlled mode. | | | on-create | `(index: number) => void` | `undefined` | Add button (+) click callback. If set, the return value will be used as the initial value of the new item. `index` is the the new item's corresponding index in the value array, which starts from 1 (the second item). | | | on-remove | `(index: number) => void` | `undefined` | Remove button (-) callback. | | | on-update:value | `(value: any) => void` | `undefined` | On value changed callback. | | ### DynamicInput Props (Input Preset) | Name | Type | Default | Description | | ----------- | --------------- | -------- | ------------------------------ | | value | `Array` | required | Value when being set manually. | | placeholder | `string` | `''` | Placeholder for each item. | ### DynamicInput Props (Pair Preset) | Name | Type | Default | Description | | --- | --- | --- | --- | | value | `Array<{ key: string, value: string }>` | required | Value when being set manually. | | key-placeholder | `string` | `''` | The placeholder of each item's key. | | value-placeholder | `string` | `''` | The placeholder of each item's value. | ### DynamicInput Slots | Name | Parameters | Description | Version | | --- | --- | --- | --- | | action | `(options: { value: any, index: number, create: (index: number) => void, remove: (index: number) => void, move: (type: 'up' \| 'down', index: number) => void })` | Customizing action; `value` and `index` are the value and index of the current item. | 2.34.4 | | default | `(options: { value: any, index: number })` | The content of each item; `value` and `index` are the value and index of the current item. | | | create-button-default | `()` | Content of create button. | 2.25.0 | | create-button-icon | `()` | Icon of create button. | 2.25.0 | --- # Dynamic Tags Turn tags to inputs and back again. ## Demos ### Basic ```vue ``` ### Max tag count ```vue ``` ### Use in form ```vue ``` ### Customizing input or trigger element You can replace a dynamic-tags input or trigger element with another component. ```vue ``` ### Custom render for each tag ```vue ``` ### Use object formatted value You can use `@create` to produce `{ label, value }` formatted value. Don't mess it up with `string` typed value. ```vue ``` ### Custom tag creation Use `on-create` to custom tags. ```vue ``` ## API ### DynamicTags Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | closable | `boolean` | `true` | Whether the tag is closable. | | | color | `{ color?: string, borderColor?: string, textColor?: string }` | `undefined` | Color of the tag. Note: it will override the color set by `type`. | | | default-value | `string[]` | `[]` | Default value. | | | disabled | `boolean` | `false` | Whether the tag is disabled. | | | input-props | `InputProps` | `undefined` | Props of internal `n-input`. | 2.25.0 | | input-class | `string` | `undefined` | Customize the class of the input. | 2.36.0 | | input-style | `string \| Object` | `undefined` | Customize the style of the input. | | | max | `number` | `undefined` | Maximum number of tags. | | | round | `boolean` | `false` | Whether the tag has rounded corners. | | | render-tag | `((tag: string, index: number) => VNodeChild) \| ((tag: { label: string, value: string }, index: number) => VNodeChild)` | `undefined` | custom render tag. | 2.27.0 | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | Size of the tag. | | | tag-class | `string` | `undefined` | Customize the class of the tag. | 2.36.0 | | tag-style | `string \| Object` | `undefined` | Customize the style of the tag. | | | type | `'default' \| 'primary' \| 'info' \| 'success' \| 'warning' \| 'error'` | `'default'` | Type of the tag. | | | value | `string[]` | `undefined` | Value if manually set. | | | on-create | `((label: string) => string) \| ((label: string) => ({ label: string, value: string }))` | `label => label` | Create derived value from input. | 2.30.4 | | on-update:value | `((value: string[]) => void) \| ((value: DynamicTagsOption[]) => void)` | `undefined` | Callback when the component's value changes. | | #### DynamicTagsOption Type ```ts export interface DynamicTagsOption { label: string value: string } ``` ### DynamicTags Slots | Name | Parameters | Description | Version | | --- | --- | --- | --- | | input | `(info: { submit: (value: any) => void, deactivate: () => void })` | Custom element(s) to replace the regular input. | `deactivate` 2.26.2 | | trigger | `(info: { activate: () => void, disabled: boolean })` | The element or component that triggers the tag to switch to an input. | | --- # Form The element to collect and validate data. > **Caveat** > > If you want to apply required rule for a form item with number typed value, you need to set ``type: 'number'`` in the rule object. ## Demos ### Inline form An example of an inline form. ```vue ``` ### Customizing rules Sometimes builtin triggers don't meet your needs. You can customize these validations by setting a custom trigger in the rules and manually triggering the validation. ```vue ``` ### Abnormal warning You may want to display warnings to the user for values that may be abnormal, but do not want the validate method to throw an exception. In this case, `FormItemRule`'s `level` attribute can help you (`level: 'warning'`). ```vue ``` ### Custom validation If you need to customize the timing and effect of a validation, use `validation-status` and `feedback`. In this case, there's usually no need for providing a `path` for the form item. ```vue ``` ### I18n Form's rule supports `renderMessage`. You can use it to render your message. ```vue ``` ### Label placement top Use `n-grid` and `n-form-item-gi` (grid item) to style the form more exactly. ```vue ``` ### Label placement left ```vue ``` ### Use form item alone You can also use `n-form-item` outside of an `n-form` element. ```vue ``` ### Async validation Supports async when the provided validator returns a `Promise`. ```vue ``` ### Disabled form ```vue ``` ### Show / hide label If `show-label` will default to `true` if not set and inherit `n-form`'s `show-label`. ```vue ``` ### Apply partial validation During validation, use the second parameter of `form.validate` to select rules, field paths, or both. A path is matched exactly against the `path` of a form item. ```vue ``` ### Custom messages You can define custom messages that are used instead of the standard ones. ```vue ``` ### Dynamic form Delete or add form items dynamically. ```vue ``` ### Custom feedback style Using `feedback-style` and `feedback-class` to custom feedback. ```vue ``` ## API ### Form Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | disabled | `boolean` | `false` | Whether to disable the form. | | | inline | `boolean` | `false` | Whether to display as an inline form. | | | label-width | `number \| string \| 'auto'` | `undefined` | The width of label. Particularly useful when `label-placement` is set to `'left'`,`'auto'` means label width will be auto adjusted. | | | label-align | `'left' \| 'right'` | `-` | Label text alignment. | | | label-placement | `'left' \| 'top'` | `'top'` | Label placement. | | | model | `Object` | `{}` | The object to get/set form item values. | | | rules | `type FormRules = { [itemValidatePath: string]: FormItemRule \| Array \| FormRules }` | `{}` | The rules to validate form items. | | | show-feedback | `boolean` | `true` | Whether to show the feedback area. | | | show-label | `boolean` | `true` | Whether to show the label. | | | show-require-mark | `boolean` | `-` | Whether to show a required symbol when a form item is required. | | | require-mark-placement | `'left' \| 'right' \| 'right-hanging'` | `'right'` | Require mark placement | `'right-hanging'` 2.24.0 | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | Size. | | | validate-messages | `FormValidateMessages` | `undefined` | Validation messages of `async-validator`. | 2.27.0 | #### FormItemRule Type > **Caveat** > > The follow table doesn't demostrate all props of rules. If you want to know all the usages, please see [async-validator](https://github.com/yiminghe/async-validator). | Property | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | asyncValidator | `(rule: FormItemRule, value: any, callback: (error?: Error) => void) => void` | `undefined` | Asynchronous validation in the form of a callback. | | | key | `string` | `undefined` | Unique key of this rule, which can be used to apply partial rules. See [Apply partial rules](https://www.naiveui.com/en-US/components/form.md#partially-apply-rules.vue) example. | | | level | `'error'` \| `'warning'` | `undefined` | Validation level. If there are already errors, `'warning'` level validation would be skipped. | | | message | `string` | `undefined` | Text to show when validation fails. | | | renderMessage | `() => VNodeChild` | `undefined` | Render function or message. | 2.29.1 | | required | `boolean` | `undefined` | Is it required. | | | trigger | `string \| Array` | `undefined` | Trigger type. | | | validator | `(rule: FormItemRule, value: any) => boolean \| Error` | `undefined` | Validation rule. | | #### FormValidateMessages Type > **Caveat** > > Please see the default messages defined in [async-validator](https://github.com/yiminghe/async-validator/blob/master/src/messages.ts) in order to see which messages you can override. ### FormItem Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | content-class | `string` | `undefined` | The class name of the content. | 2.43.0 | | content-style | `string \| object` | `undefined` | The style of the content. | 2.43.0 | | feedback | `string` | `undefined` | The feedback message of the form item. If set, it will replace any result of rule-based validation. | | | feedback-class | `string` | `undefined` | Feedback check vertical display positioning | 2.38.2 | | feedback-style | `string \| object` | `undefined` | Feedback check horizontal display positioning | 2.38.2 | | first | `boolean` | `false` | Whether to only show the first validation error message. | | | ignore-path-change | `boolean` | `false` | Usually, changing `path` will cause a re-render and naive-ui will clear the validation result. Setting `ignore-path-change` to `true` will disable that behavior. | | | label | `string` | `undefined` | Label. | | | label-align | `'left' \| 'right'` | `undefined` | Text alignment inside the label. If not set, it will inherit the parent form's `label-align`. | | | label-placement | `'left' \| 'top'` | `undefined` | If not set, it will inherit the parent form's `label-placement`. | | | label-props | `LabelHTMLAttributes` | `undefined` | HTML attributes of the label element inside form item. | 2.24.0 | | label-style | `CSSProperties \| string` | `undefined` | Label style. | | | label-width | `number \| string \| 'auto'` | `undefined` | If not set, it will inherit the parent form's `label-width`,`'auto'` means label width will be auto adjusted. | | | path | `string` | `undefined` | The path to use in the parent form's model object. | | | required | `boolean` | `false` | Whether to show the "required" symbol. Note: a required rule has higher priority than this prop & this prop **won't** have any effect on validation. Validation still depends on rules. | | | rule | `FormItemRule \| Array` | `undefined` | The rule to validate this form item. It will be merged with the rules acquired by `rule-path` from the parent form's rules. It's recommended to set all rules on the parent form. | | | rule-path | `string` | `undefined` | The path to get rules from the parent form's rule object. If not set, it will use the path of the parent form item instead. | | | show-feedback | `boolean` | `true` | Whether to show the feedback area. | | | show-label | `boolean` | `true` | Whether to show a label. If not set, it will inherit `show-label` from the parent form. | | | show-require-mark | `boolean` | `-` | Whether to show required symbol. If not set, it will use `show-require-mark` from the parent form. | | require-mark-placement | `'left' \| 'right' \| 'right-hanging'` | `'right'` | Require mark placement. If not set, it will use `require-mark-placement` from the parent form. | `'right-hanging'` 2.24.0 | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | Size. | | | validation-status | `'error' \| 'success' \| 'warning'` | `undefined` | The validation status of the form item. If set, it will replace the result of the rule-based validation. | | ### FormItemGi Props Accept all props from FormItem & [GridItem](https://www.naiveui.com/en-US/components/grid.md#GridItem-Props) ### Form Methods > **Caveat on Validate Method** > > By default, validation will use all rules regardless of the triggers of the rules. | Name | Type | Description | Version | | --- | --- | --- | --- | | validate | `(validateCallback?: (errors: Array \| undefined, extra: { warnings: Array \| undefined }) => void, filter?: ((rule: FormItemRule) => boolean) \| Array \| { paths: Array, shouldRuleBeApplied: (rule: FormItemRule) => boolean }) => Promise<{ warnings: Array \| undefined }>` | Validate the form. Pass field paths to validate matching form items, or pass an object to filter both form items and rules. Paths match form item `path` values exactly. The rejection value type of returned promise is `Array`. | `warnings` `2.37.1`, path filter `2.45.0` | | restoreValidation | `() => void` | Restore validate. | | | invalidateLabelWidth | `() => void` | Recalculate label widths of all form items. Useful when using `label-width="auto"` and the label content changes dynamically. | NEXT_VESION | ### FormItem, FormItemGi Methods | Name | Type | Description | Version | | --- | --- | --- | --- | | validate | `(options: { trigger?: string, callback?: (errors: FormValidationError \| undefined, extra: { warnings: FormValidationError \| undefined }) => void, shouldRuleBeApplied?: FormItemRule => boolean, options?: AsyncValidatorOptions }) => Promise<{ warnings: FormValidationError \| undefined }>` | Validate the form item. The rejection value type of returned promise is `FormValidationError`. If trigger is not set, all rules of the item will be applied. `shouldRuleBeApplied` can filter rules after they are filtered by the trigger. | `warnings` `2.37.1` | | restoreValidation | `() => void` | Restore validate. | | | invalidateLabelWidth | `() => void` | Recalculate the label width of this form item. Useful when using `label-width="auto"` and the label content changes dynamically. | NEXT_VESION | To find out more about AsyncValidatorOptions, see [async-validator](https://github.com/yiminghe/async-validator). ### Form Slots | Name | Parameters | Description | | ------- | ---------- | ----------- | | default | `()` | Content. | ### FormItem, FormItemGi Slots | Name | Parameters | Description | Version | | -------- | ---------- | -------------- | ------- | | default | `()` | Content. | | feedback | `()` | Feedback. | 2.24.0 | | label | `()` | Label content. | | --- # Input Many years ago, inputs were just punched cards. ## Demos ### Basic Basic use of `n-input`. ```vue ``` ### Size ```vue ``` ### Round corner Inputs can have rounded corners. ```vue ``` ### Prefix & suffix Set a prefix and/or suffix for the input. ```vue ``` ### Loading `input` has a loading state. Note: When using `clearable`, `suffix` and `loading` at the same time, and `loading` is `false`, there will be a space between the clear button and the suffix, if you want to remove the whitespace, `loading` should be set to `undefined` when stopping loading. ```vue ``` ### Password ```vue ``` ### Disabled Inputs can also be disabled. ```vue ``` ### Clearable Make the input clearable after a value is set. ```vue ``` ### Autosize Autosize the input. ```vue ``` ### Pairwise value ```vue ``` ### Input group ```vue ``` ### Passively activated If you want to activate the input by pressing enter after it's focused, use `passively-activated`. Use Tab to focus on the next input(s). ```vue ``` ### Word limit Don't waste words. ```vue ``` ### Imperative handle Clear. Focus. Blur. Selection. Scroll. ```vue ``` ### Events ```vue ``` ### Input props Input element has some special attributes, such as `auto-complete` or `type`. You can use `input-props` to set it. ```vue ``` ### Validation status Validation status can be applied outside form. ```vue ``` ### Limit input format Use `allow-input` to limit input value to desired format. You can use it to achieve trim effect. ```vue ``` ### Count graphemes Browser's default `maxlength` and `minlength` and naive-ui's builtin character count method can't split all string correctly. You can use `count-graphemes` count to count graphemes correctly. ```vue ``` ## API ### Input Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | allow-input | `(value: string) => boolean` | `undefined` | Check the incoming value, if it returns `false`, input will not be accepted. | 2.30.4 | | autofocus | `boolean` | `false` | Whether to autofocus. | | | autosize | `boolean \| { minRows?: number, maxRows?: number }` | `false` | Sizing property for when the input is of type `textarea`. e.g. `{ minRows: 1, maxRows: 3 }`. | | | clearable | `boolean` | `false` | Whether the input is clearable. | | | count-graphemes | `(value: string) => number` | `undefined` | Count graphemes of input value. If it's set, native `maxlength` and `minlength` won't be used. | 2.34.0 | | default-value | `string \| [string, string] \| null` | `null` | Default value when not manually set. | | | disabled | `boolean` | `false` | Whether to disable the input. | | | input-props | `InputHTMLAttributes \| TextareaHTMLAttributes` | `undefined` | The dom props of the input element inside the component. This is disabled if the `pair` property is true. For avaiable attributes, [see here](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input). Warning:It won't override internal props with the same name (except `type`). | | | loading | `boolean` | `undefined` | Set loading state. If set (true/false), the element will always take up enough space for the loading indicator. | | | maxlength | `number` | `undefined` | Maximum input length. | | | minlength | `number` | `undefined` | Minimum input length. | | | pair | `boolean` | `false` | Whether to use the pairwise type input. | | | passively-activated | `boolean` | `false` | Whether to passively activate the input. | | | placeholder | `string \| [string, string]` | `undefined` | Placeholder of input. When `pair` is `true`, this is an array. | | | readonly | `boolean` | `false` | Set the readonly state. | | | render-count | `(props: { value: string }) => void` | `undefined` | Render function of word count. | 2.32.2 | | round | `boolean` | `false` | Use a rounded input style. | | | rows | `number` | `3` | Rows property for when the input is of type `textarea`. | | | separator | `string` | `undefined` | The separator between pairwise inputs. | | | show-count | `boolean` | `false` | Whether to show the word count. | | | show-password-on | `'click' \| 'mousedown'` | `undefined` | The event to show the password. | | | size | `'tiny' \| 'small' \| 'medium' \| 'large'` | `'medium'` | Input size. | | | status | `'success' \| 'warning' \| 'error'` | `undefined` | Validation status. | 2.25.0 | | type | `'text' \| 'password' \| 'textarea'` | `'text'` | Input type. | | | value | `string \| [string, string] \| null` | `undefined` | Manually set the input value. When `pair` is `true`, this is an array. | | | on-blur | `() => void` | `undefined` | Callback triggered when the input is blurred. | | | on-change | `(value: string \| [string, string]) => void` | `undefined` | Callback triggered when native change event is fired. | | | on-clear | `() => void` | `undefined` | Callback triggered when the input is cleared. | | | on-focus | `() => void` | `undefined` | Callback triggered when the input is focussed on. | | | on-input | `(value: string \| [string, string]) => void` | `undefined` | Callback triggered when the input gets user input. | | | on-update:value | `(value: string \| [string, string]) => void` | `undefined` | Callback triggered when the input value changes. | | ### Input Slots | Name | Parameters | Description | Version | | --- | --- | --- | --- | | clear-icon | `()` | Custom clear icon. | 2.29.0 | | count | `(props: { value: string })` | Word count. | | | password-invisible-icon | `()` | Password toggle icon when password is invisible. | 2.27.0 | | password-visible-icon | `()` | Password toggle icon when password is visible. | 2.27.0 | | prefix | `()` | Prefix content slot. | | | separator | `()` | The separator content of the input, only works when `pair` is true. This will take priority over the separator property. | | | suffix | `()` | Suffix content slot. | | ### InputGroup Slots | Name | Parameters | Description | | ------- | ---------- | ------------------------------- | | default | `()` | The content of the input group. | ### InputGroupLabel Slots | Name | Parameters | Description | | ------- | ---------- | ------------------------------------- | | default | `()` | The content of the input group label. | ### Input Methods | Name | Type | Description | Version | | --- | --- | --- | --- | | blur | `() => void` | Blur the input element. | | | clear | `() => void` | Clear input value. | 2.37.0 | | focus | `() => void` | Focus the input element. | | | scrollTo | `(options: { left?: number, top?: number, behavior?: 'auto' \| 'smooth' }) => void` | Scroll To. | 2.32.0 | | select | `() => void` | Select the input element. | | --- # Input Number If you just want a number, this is for you. ## Demos ### Basic ```vue ``` ### Disabled ```vue ``` ### Custom parsing You can use `parse` and `format` to custom parsing & display. For example add thousand separator. Usually they should be set together, especially you have a custom `validator` set. Use `parse` and `format` will disable `update-value-on-input`. ```vue ``` ### Precision Set the `precision` property to control the numerical precision. Use `precision` will disable `update-value-on-input`. ```vue ``` ### Event Blur & change events are exposed. ```vue ``` ### Prefix & suffix Add prefix and suffix contents. ```vue ``` ### Button placement Button can be placed at both ends. ```vue ``` ### Loading ```vue ``` ### Min and max You can set minimum and maximum values too. ```vue ``` ### Size ```vue ``` ### Step Set how much the buttons change the value. ```vue ``` ### Validator ```vue ``` ### Hide button Use `show-button` prop to control whether to show control buttons. ```vue ``` ### Disable keyboard arrow up & down Set `:keyboard="{ ArrowUp: false, ArrowDown: false }"` to disabled keyboard arrow up & down. ```vue ``` ### Timing to change Set `update-value-on-input` to `false`, the value won't be changed on input. ```vue ``` ### Validation status Validation status can be applied outside form. ```vue ``` ### Custom Icon ```vue ``` ## API ### InputNumber Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | autofocus | `boolean` | `false` | Whether to autofocus. | 2.26.1 | | bordered | `boolean` | `true` | Whether to show a border. | | | button-placement | `'both' \| 'right'` | `'right'` | Placement of add & minus button. | 2.29.1 | | clearable | `boolean` | `false` | Whether the input is clearable. | | | default-value | `number \| null` | `null` | Default value when not manually set. | | | disabled | `boolean` | `false` | Whether to disable the input. | | | format | `(value: number \| null) => string` | `undefined` | Method to format value. If it's set, `update-value-on-input` will be disabled. | 2.30.0 | | input-props | `InputHTMLAttributes` | `undefined` | The dom props of the input element inside the component. For avaiable attributes, [see here](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input). Warning:It won't override internal props with the same name (except `type`). | 2.37.0 | | keyboard | `{ ArrowUp?: boolean, ArrowDown?: boolean }` | `{}` | Control the keyboard behavior. If you set corresponding to false, the keyboard behavior will be disabled. | | | loading | `boolean` | `undefined` | Set loading state. If set (true/false), the element will always take up enough space for the loading indicator. | | | max | `number` | `undefined` | The max value. | | | min | `number` | `undefined` | The min value. | | | parse | `(input: string) => number \| null` | `undefined` | Method to parse input string. If it's set, `update-value-on-input` will be disabled. | 2.30.0 | | placeholder | `string` | `'Please Input'` | Placeholder. | | | precision | `number` | `undefined` | Precision of input value. If it's set, `update-value-on-input` will be disabled. | 2.30.0 | | round | `boolean` | `undefined` | Use a rounded input style. | 2.39.0 | | readonly | `boolean` | `false` | Whether it's readonly. | | | show-button | `boolean` | `true` | Whether to show increase/decrease buttons. | | | size | `'tiny' \| 'small' \| 'medium' \| 'large'` | `'medium'` | The size of input box. | | | status | `'success' \| 'warning' \| 'error'` | `undefined` | Validation status. | 2.27.0 | | step | `number` | `1` | The number which the current value is increased or decreased on key or button press. It can be an integer or a decimal. | | | update-value-on-input | `boolean` | `true` | Whether to change the value on input if the input value is valid. | | | validator | `(value) => boolean` | `undefined` | Setup custom validation. | | | value | `number \| null` | `undefined` | Manually set the input value. | | | on-blur | `(event: FocusEvent) => void` | `undefined` | Callback triggered when the input is blurred. | | | on-clear | `() => void` | `undefined` | Callback triggered when the input is cleared. | | | on-focus | `(event: FocusEvent) => void` | `undefined` | Callback triggered when the input is focussed on. | | | on-update:value | `(value: number \| null) => void` | `undefined` | Callback triggered when the input value changes. | | ### InputNumber Slots | Name | Parameters | Description | Version | | ---------- | ---------- | ------------------------- | ------- | | add-icon | `()` | icon of the add button. | 2.28.1 | | minus-icon | `()` | icon of the minus button. | 2.28.1 | | prefix | `()` | Prefix content slot. | | | suffix | `()` | Suffix content slot. | | ### InputNumber Methods | Name | Type | Description | | ----- | ------------ | ----------------------- | | blur | `() => void` | Blur the input number. | | focus | `() => void` | Focus the input number. | --- # Input OTP InputOTP is used to enter one time password. Available since `2.41.1`. ## Demos ### Basic The number of characters is defined by the `length` prop, which by default is `6`. ```vue ``` ### Status Readonly, disabled, warning, error status. ```vue ``` ### Mask Set `mask=true` to turn on input mask. ```vue ``` ### Custom rendering By using `default` slot, you can custom UI to replace default design. ```vue ``` ### Block `block` property will make the `n-input-otp` fit to its parent width. ```vue ``` ### Size ```vue ``` ### Use with form An example for using together with `n-form`. ```vue ``` ### Limit input format Use `allow-input` to limit input value to desired format. ```vue ``` ## API ### InputOTP Props | Name | Type | Type Alais | Default | Description | Version | | --- | --- | --- | --- | --- | --- | | allow-input | `(char: string, index: number, currentValue: string[]) => boolean` | `InputOtpAllowInput` | `undefined` | Check the incoming value, if it returns `false`, input will not be accepted. | 2.41.1 | | block | `boolean` | | `false` | Whether to fit its width to its parent's width. | 2.42.0 | | default-value | `string[]` | | `[]` | Default value. | 2.41.1 | | disabled | `boolean` | | `false` | Whether the component is disabled. | 2.41.1 | | gap | `string \| number` | | `undefined` | Gap between different input. If not specified, the default styling would be applied. | 2.41.1 | | length | `number` | | `6` | Number of characters to initiate. | 2.41.1 | | mask | `boolean` | | `false` | Whether to enable password mode. | 2.41.1 | | placeholder | `string` | | `''` | Input placeholder. | 2.41.1 | | readonly | `boolean` | | `false` | Whether the component is readonly. | 2.41.1 | | size | `'small' \| 'medium' \| 'large'` | `InputOtpSize` | `'medium'` | Size of the component. | 2.41.1 | | status | `'success' \| 'warning' \| 'error'` | `FormValidationStatus` | `undefined` | The validation status of the component. | 2.41.1 | | value | `string \| null` | | `undefined` | Value of the component (in controlled mode). | 2.41.1 | | on-blur | `(event: FocusEvent, index: number) => void` | `InputOtpOnBlur` | `undefined` | Callback fired when the focus is out of the component. | 2.41.1 | | on-finish | `(value: string[]) => void` | `InputOtpOnFinish` | `undefined` | Callback fired when all child inputs are settled. | 2.41.1 | | on-focus | `(event: FocusEvent, index: number) => void` | `InputOtpOnFocus` | `undefined` | Callback fired when the focus is moved from outside to the component. | 2.41.1 | | on-update:value | `(value: string[], meta: { diff: string, index: number, source: 'input' \| 'delete' \| 'paste' }) => void` | `InputOtpOnUpdateValue`, `InputOtpOnUpdateValueMeta`, `InputOtpOnUpdateValueMetaSource` | `undefined` | Callback fired when user inputs value. `meta.index` is the start index of the value change.`meta.diff` is the content that changes. `meta.source` is the reason of the value change. If reason is `'delete'`, `meta.diff` is `''`. If reason is `'paste'`, `meta.diff` is the final accepted part of the paste content. | 2.41.1 | ### InputOTP Slots | Name | Parameters | Type Alias | Description | Version | | --- | --- | --- | --- | --- | | default | `(props: InputProps & { index: number, ref: (inst: InputInst) => void })` | `InputOtpDefaultSlot` | Input area. | 2.41.1 | ### InputOTP Methods | 名称 | 类型 | 说明 | 版本 | | --- | --- | --- | --- | | focusOnChar | `(charIndex: number) => void` | Focus on a certain input box. | 2.43.0 | --- # Mention A year ago, my product manager asked me if I could implement this feature. Back then, I recommended just using multiple selects as a workaround. ## Demos ### Basic usage If `label` is a render function, the `value` property will be used for matching. ```vue ``` ### Textarea The input `type` can be set to `'textarea'`. ```vue ``` ### Load remote options Load options asynchronously. ```vue ``` ### Autosize ```vue ``` ### Work with form ```vue ``` ### Render label If the `option.label` property is not a string, the `option.value` property will be used for matching by default. ```vue ``` ### Custom trigger prefix Use `prefix` to set the trigger character(s). ```vue ``` ### Manually trigger focus and blur You may want to trigger `focus` and `blur` manually? ```vue ``` ### Validation status Validation status can be applied outside form. ```vue ``` ## API ### Mention Props Mention requires `v2.2.0` and above. | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | autosize | `boolean \| { maxRows?: number, minRows?: number }` | `false` | Autosize. | | | options | `MentionOption[]` | `[]` | Mention options list. | | | type | `'text' \| 'textarea'` | `'text'` | Input type. | | | separator | `string` | `' '` | Character to split mentions. The string length must be exactly 1. | | | bordered | `boolean` | `true` | Whether to display the border of the input element. | | | disabled | `boolean` | `false` | Whether to disable the input element. | | | default-value | `string` | `''` | Default value when the value is not manually set. | | | filter | `(pattern: string, option: MentionOption) => boolean` | Default filter method | Method to filter options corresponding to `pattern`. | 2.38.2 | | loading | `boolean` | `false` | Whether the selection panel of mentions is in a loading state. | | | prefix | `string \| string[]` | `'@'` | Prefix character(s) to trigger mentions. The string length(s) must be exactly 1. | | | placeholder | `string` | `''` | Placeholder. | | | placement | `'top-start' \| 'top' \| 'top-end' \| 'right-start' \| 'right' \| 'right-end' \| 'bottom-start' \| 'bottom' \| 'bottom-end' \| 'left-start' \| 'left' \| 'left-end'` | `'bottom-start'` | Selection panel's placement . | 2.25.0 | | render-label | `(option: MentionOption) => VNodeChild` | `undefined` | Options' labels render function. | | | scrollbar-props | `ScrollbarProps` | `undefined` | See [Scrollbar props](https://www.naiveui.com/en-US/components/scrollbar.md#Scrollbar-Props) | 2.44.0 | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | Input size. | | | status | `'success' \| 'warning' \| 'error'` | `undefined` | Validation status. | 2.27.0 | | to | `string \| HTMLElement \| false` | `body` | Container node of the menu. `false` will keep it not detached. | | | value | `string \| null` | `undefined` | Manually set input value. | | | on-update:show | `(show: boolean) => void` | `undefined` | Callback when the selection panel of mentions is shown or hidden. | 2.34.0 | | on-update:value | `(value: string) => void` | `undefined` | Triggered when the input box value is updated. | | | on-select | `(option: MentionOption, prefix: string) => void` | `undefined` | Triggered when the input box is selected. | | | on-focus | `(e: FocusEvent) => void` | `undefined` | Triggered when the input box is focussed on. | | | on-search | `(pattern: string, prefix: string) => void` | `undefined` | Triggered when searching in the input box. | | | on-blur | `(e: FocusEvent) => void` | `undefined` | Triggered when the input box loses focus. | | ### MentionOption Properties | Name | Type | Description | | --- | --- | --- | | class | `string` | Option class property. | | disabled | `boolean` | Option disabled state. | | label | `string \| (option: MentionOption) => VNodeChild` | Option label. | | render | `(option: MentionOption) => VNodeChild` | Support custom options via `render` rendering function. | | style | `string` | Option style property. | | value | `string` | Option value. Must be unique. | ### Mention Methods | Name | Type | Description | | ----- | ------------ | -------------------------------- | | focus | `() => void` | Manually focus on the component. | | blur | `() => void` | Manually blur the component. | ### Mention Slots | Name | Parameters | Description | | ----- | ---------- | --------------------------- | | empty | `()` | Slot when menu has no data. | --- # Radio When I was young, I loved listening to the radio, such as FM 106.8 or FM 92.1. ## Demos ### Basic ```vue ``` ### Group A radio group looks elegant. ```vue ``` ### Using Options Pass option data directly through the `options` prop. You can also customize field names with `label-field` and `value-field`. ```vue ``` ### Button group Sometimes a radio button group can look more elegant. ```vue ``` ### Size Choose the size you want. ```vue ``` ## API ### Radio Props, RadioButton Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | checked | `boolean` | `undefined` | Checked state. | | | default-checked | `boolean` | `false` | Default checked state. | | | disabled | `boolean` | `false` | Disabled state. | | | label | `string` | `undefined` | Radio label. If not set, render default slot content, if both, use default slot content first. | 2.28.0 | | name | `string` | `undefined` | The name attribute of the radio element. If not set, name of `radio-group` will be used. | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | Size. | | | value | `string \| number \| boolean` | `'on'` | Checked value. | `boolean` 2.33.0 | | on-update:checked | `(check: boolean) => void` | `undefined` | Callback method triggered when a selection change occurs. | | ### RadioGroup Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | disabled | `boolean` | `false` | Disabled state. | | | default-value | `string \| number \| boolean \| null` | `null` | Default checked value. | | | label-field | `string` | `'label'` | The field name of option labels in `options`. | 2.45.0 | | name | `string` | `undefined` | The name attribute of the radio elements inside the group. | | | options | `Array<{ label?: string, value: string \| number \| boolean, disabled?: boolean }>` | `undefined` | Options for the radio group. When set, the default slot is ignored. | 2.45.0 | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | Size. | | | value | `string \| number \| boolean \| null` | `null` | Checked value. | | | value-field | `string` | `'value'` | The field name of option values in `options`. | 2.45.0 | | on-update:value | `(value: string \| number \| boolean) => void` | `undefined` | Callback method triggered when a selection change occurs. | | --- # Rate Hint: If you are not very confident, think twice before changing the star's color. That can lead to a disaster. ## Demos ### Basic ```vue ``` ### Size Rate has `small`, `medium` and `large` size. Also you can use number to specify the size. ```vue ``` ### Color This can end in disaster. ```vue ``` ### Icon The content of the default slot will be used as the icon. ```vue ``` ### Allow Selecting Half Star ```vue ``` ### Readonly ```vue ``` ### Clearable After `clearable` is set, you can click at current value's corresponding value to reset value to `null`. ```vue ``` ### Hover Value Listen to hover value changes via `on-update:hover-value`. ```vue ``` ## API ### Rate Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | allow-half | `boolean` | `false` | Allow activating half of the icon. | | | clearable | `boolean` | `false` | Whether the rate is clearable. Value will be set to `null` if you click on current value's corresponding icon. | 2.33.0 | | color | `string` | `undefined` | Activated icon color. This supports the formats: `#FFF`, `#FFFFFF`, `yellow`, `rgb(0, 0, 0)`. | | | count | `number` | `5` | Number of icons (max rating). | | | default-value | `number \| null` | `null` | Default value of activated icons. Before 2.33.0 default value is `null`. | 2.33.0 `null` | | readonly | `boolean` | `false` | Readonly state. | | | size | `'small' \| 'medium' \| 'large' \| number` | `'medium'` | Icon size. | | | value | `number \| null` | `undefined` | Value of activated icons. | | | on-clear | `() => void` | `undefined` | Callback on value is cleared. | 2.33.0 | | on-update:hover-value | `(value: number \| null) => void` | `undefined` | Callback when the hover value changes. | 2.45.0 | | on-update:value | `(value: number) => void` | `undefined` | Callback on the value (rating) is changed. | | ### Rate Slots | Name | Parameters | Description | | ------- | --------------------------- | ----------------------- | | default | `(info: { index: number })` | The icon of the rating. | --- # Select Select something! ## Demo ### Basic Basic usage of `n-select`. ```vue ``` ### Size ```vue ``` ### Multiple select Allow the selection of multiple values. ```vue ``` ### UpdateValue event Why make the `update:value` event an example? Because there's so little to write. ```vue ``` ### Filterable Go go go, Filter. ```vue ``` ### Create option dynamically Use `tag` & `filterable` properties to create options dynamically. ```vue ``` ### Menu width The options menu width can be made to fit its content. Using this disables virtual scrolling. ```vue ``` ### Remote (single) Asynchronous example for a single select case. ```vue ``` ### Remote (multiple) Asynchronous options example for a multiple select case. ```vue ``` ### Clearable Make the select clearable. Remember you can only clear a select that has a value. ```vue ``` ### Scroll event A colleague of mine wanted to use a scroll event for loading options asynchronously. Here's that example. ```vue ``` ### Group Options can also be grouped together. ```vue ``` ### Lots of options 1000 times the answer to everything. ```vue ``` ### Customize option rendering After much deliberation, I decided to drop the slot API for rendering options; however, using `render-label`, `style`, and/or `class` properties you can do almost anything. ```vue ``` ### Customize arrow Make arrow a bit different. ```vue ``` ### Action slot Is there anybody who needs an action slot on a select menu? ```vue ``` ### Fallback option If you don't need fallback options, setting `fallback-option` to `false` ensures that only an option with a matching value will be displayed. If no option has that value, the selected value will be cleared. ```vue ``` ### Max tag count Maximum selected options to display. This can be a fixed number or the string `responsive` to set a responsive max count. ```vue ``` ### Add tooltip to option Use the `render-option` property to control rendering of the entire option. ```vue ``` ### Customize tag rendering Give the tag a little color. ```vue ``` ### Focus & blur manually ```vue ``` ### Select person I've found that people often want to make a people picker. Here is an example that shows you how that can be done with a select. ```vue ``` ### Use as tag input box Use `tag` and `:show="false"` to use select as a tag input box. ```vue ``` ### Customizing field Various data would come from backend. ```vue ``` ## API ### Select Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | consistent-menu-width | `boolean` | `true` | Whether the menu keeps its width the same as the select trigger element. Setting it to `false` will also disable `virtual-scroll`. | | | children-field | `string` | `'children'` | Field name of group option children. | 2.29.1 | | clearable | `boolean` | `false` | Whether the value is clearable. | | | clear-created-options-on-clear | `boolean` | `true` | When `tag` and `clearable` are enabled, whether to clear created options when clearing. | 2.44.0 | | clear-filter-after-select | `boolean` | `true` | When multiple and filter is true, whether to clear filter keyword after select an option. | 2.25.2 | | default-value | `Array \| string \| number \| null` | `null` | Default value. | | | disabled | `boolean` | `false` | Whether to disable the select. | | | ellipsis-tag-popover-props | `PopoverProps` | `undefined` | `popover` props of the preview ellipsis tag. | 2.37.0 | | fallback-option | `false \| (value: string \| number) => SelectOption` | `value => ({ label: '' + value, value })` | The option to be created using the value which has no corresponding option value. If set to `false`, the fallback option won't be created and displayed. | | | filterable | `boolean` | `false` | Whether options can be filtered. | | | filter | `(pattern: string, option: Object) => boolean` | String search method. | Filter function. | | | ignore-composition | `boolean` | `true` | Ingore IME's composition status. By default `filter` won't be triggered by input event under compositions. | 2.33.4 | | input-props | `InputHTMLAttributes` | `undefined` | The attributes of input element in the trigger. It only works when the select is filterable. | | | keyboard | `boolean` | `true` | Whether to allow keyboard control. | 2.34.4 | | label-field | `string` | `'label'` | Field name of option label. | 2.29.1 | | loading | `boolean` | `false` | Whether to show a loading state. | | | max-tag-count | `number \| 'responsive'` | `undefined` | Maximum selected values to display while in `multiple` mode. `responsive` will keep all the tags in single line. | | | menu-props | `HTMLAttributes` | `undefined` | The menu's dom props. | | | menu-size | `'tiny' \| 'small' \| 'medium' \| 'large'` | `'medium'` | Size of select menu. | 2.40.0 | | multiple | `boolean` | `false` | Whether to allow selecting multiple values. | | | node-props | `(option: SelectOption \| SelectGroupOption) => object` | `undefined` | Option's DOM attrs generator. | 2.32.2 | | options | `Array` | `[]` | Options that can be selected. For more details see SelectOption Properties (below). | | | placeholder | `string` | `'Please Select' (i18n)` | Placeholder. | | | placement | `'top-start' \| 'top' \| 'top-end' \| 'right-start' \| 'right' \| 'right-end' \| 'bottom-start' \| 'bottom' \| 'bottom-end' \| 'left-start' \| 'left' \| 'left-end'` | `'bottom-start'` | Option menu's placement. | 2.25.0 | | remote | `boolean` | `false` | Allows options to be fetched asynchronously. Note that if `remote` is set, `filter` & `tag` won't work on `options`. | | | render-label | `(option: SelectOption \| SelectGroupOption, selected: boolean) => VNodeChild` | `undefined` | Render function for each option label. | | | render-option | `(info: { node: VNode, option: SelectOption \| SelectGroupOption, selected: boolean }) => VNodeChild` | `undefined` | Render function for each option. | | | render-tag | `(props: { option: SelectBaseOption, handleClose: () => void }) => VNodeChild` | `undefined` | Render function for each option tag. | | | reset-menu-on-options-change | `boolean` | `true` | Whether to reset menu status on options change, for example, scroll status. | 2.24.2 | | scrollbar-props | `ScrollbarProps` | `undefined` | See [Scrollbar props](https://www.naiveui.com/en-US/components/scrollbar.md#Scrollbar-Props) | 2.44.0 | | show | `boolean` | `undefined` | Whether to show/open the option menu. | | | show-arrow | `boolean` | `true` | Whether to show the dropdown arrow. | | | show-checkmark | `boolean` | `true` | Whether to show checkmark. | 2.33.4 | | show-on-focus | `boolean` | `false` | Whether to show menu on focus. | 2.34.3 | | size | `'tiny' \| 'small' \| 'medium' \| 'large'` | `'medium'` | Size of the select input. | | | status | `'success' \| 'warning' \| 'error'` | `undefined` | Validation status. | 2.27.0 | | tag | `boolean` | `false` | Whether users can create new options. This should be used with `filterable`. | | | to | `string \| HTMLElement \| false` | `body` | Container node of the menu. `false` will keep it not detached. | | | value | `Array \| string \| number \| null` | `undefined` | Value when being manually set. | | | value-field | `string` | `'value'` | Field name of option value. | 2.29.1 | | virtual-scroll | `boolean` | `true` | Whether to enable virtual scrolling. | | | on-blur | `() => void` | `undefined` | Callback triggered when the selection element is blurred. | | | on-clear | `() => void` | `undefined` | Callback triggered when the selection element is cleared. | | | on-create | `(label: string) => SelectOption` | `label => ({ label, value: label })` | How to create an option when you type in a custom option. Note that `filter` will be applied to the created option too. And you'd better make sure that the value of the created option is not the same as any other option. Should be used with `tag` prop. | | | on-focus | `() => void` | `undefined` | Callback triggered when the selection element is focussed on. | | | on-scroll | `(e: ScrollEvent) => void` | `undefined` | Callback triggered when the options menu is scrolled. | | | on-search | `(value: string) => void` | `undefined` | Callback triggered when a search is conducted. | | | on-update:show | `(show: boolean) => void` | `undefined` | Callback on menu open status change. | 2.24.2 | | on-update:value | `(value: Array \| string \| number \| null, option: SelectBaseOption \| null \| SelectBaseOption[]) => void` | `undefined` | Callback triggered when the selected value is updated. | | #### SelectOption Properties | Name | Type | Description | | --- | --- | --- | | class | `string` | Customize the option's class. | | disabled | `boolean` | Whether to disable the option. | | label | `string \| ((option: SelectOption, selected: boolean) => VNodeChild)` | Label of the option. Note that if you are using the `render` function, the default filter will filter the option. | | render | `(info: { node: VNode, option: SelectOption, selected: boolean }) => VNodeChild` | Render the entire option. | | style | `string \| CSSProperties` | Customize the option's style. | | value | `string \| number` | Should be unique for each option. | #### SelectGroupOption Properties | Name | Type | Description | | --- | --- | --- | | children | `Array` | Child select options. | | label | `string \| ((option: SelectGroupOption) => VNodeChild)` | Label of the group. | | key | `string \| number` | Should be unique for each option. | | render | `(info: { node: VNode, option: SelectOption, selected: boolean }) => VNodeChild` | Render the entire option. | | type | `'group'` | Type of the group option. | ### Select Slots | Name | Parameters | Description | Version | | ------ | ---------- | -------------------------------------- | ------- | | header | `()` | Header menu slot. | 2.37.0 | | action | `()` | Options menu slot. | | | empty | `()` | Empty state slot for the options menu. | | | arrow | `()` | Arrow icon slot. | 2.24.2 | ### Select Methods | Name | Type | Description | Version | | ---------- | ------------ | ------------ | ------- | | focus | `() => void` | Focus. | 2.24.2 | | focusInput | `() => void` | Input focus. | 2.35.0 | | blur | `() => void` | Blur. | 2.24.2 | | blurInput | `() => void` | Input blur. | 2.35.0 | --- # Slider As far as I know, it is always used as a volume control. ## Demos ### Basic ```vue ``` ### Range ```vue ``` ### Mark ```vue ``` ### Restrict selectable values Set `step="mark"` to restrict the selectable values to those provided by the mark prop. ```vue ``` ### Disabled ```vue ``` ### Disable tooltip Set `:tooltip="false"` to disabled the tooltip. ```vue ``` ### Format tooltip ```vue ``` ### Reverse Set `reverse` to invert the track. ```vue ``` ### Vertical Set `vertical` to enable the vertical mode. Its height depends on the height of the container by default, and you can also customize the height. ```vue ``` ### Always show tooltip Set `show-tooltip` to always show tooltip. ```vue ``` ### Customize handle You can use `handle` slot to customize handle button. ```vue ``` ### Custom Mark You can use `marks` prop to customize handle button. ```vue ``` ## API ### Slider Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | default-value | `number \| [number, number] \| null` | `null` | Default value. | | | disabled | `boolean` | `false` | Whether the slider is disabled. | | | format-tooltip | `(value: number) => string \| number` | `undefined` | Format tooltip. | | | keyboard | `boolean` | `true` | Whether the slider can be controlled keyboard. | 2.33.0 | | marks | `{ [markValue: number]: string \| (() => VNodeChild) }` | `undefined` | Marks of the slider | Render function since 2.40.0 | | max | `number` | `100` | Max value of the slider. | | | min | `number` | `0` | Min value of the slider. | | | placement | `'top-start' \| 'top' \| 'top-end' \| 'right-start' \| 'right' \| 'right-end' \| 'bottom-start' \| 'bottom' \| 'bottom-end' \| 'left-start' \| 'left' \| 'left-end'` | `undefined` | Tooltip's placement | 2.25.0 | | range | `boolean` | `false` | Whether the slider uses range value. | | | reverse | `boolean` | `false` | Whether to reverse the track. | | | show-tooltip | `boolean` | `false` | Whether to always show tooltip. Only work with non-range slider. | 2.24.2 | | step | `number \| 'mark'` | `1` | Step of the slider. | | | tooltip | `boolean` | `true` | Whether to show tooltip. | | | vertical | `boolean` | `false` | Whether to enable vertical mode. | | | value | `number \| [number, number] \| null` | `undefined` | Value of the slider. | | | on-update:value | `(value: number \| [number, number]) => void` | `undefined` | Callback on value update. | | | on-dragstart | `() => void` | `undefined` | Callback function of dragging start. | 2.36.0 | | on-dragend | `() => void` | `undefined` | Callback function of dragging end. | 2.36.0 | ### Slider Slots | Name | Parameters | Description | Version | | ----- | ---------- | -------------------- | ------- | | thumb | `()` | Thumb of the slider. | 2.30.4 | --- # Switch I have a Nintendo Switch, but don't have time to play it. This reminds me of my childhood when I played NDS... a happier time. ## Demos ### Basic ```vue ``` ### Size ```vue ``` ### Content Add switch content. ```vue ``` ### Loading ```vue ``` ### Event ```vue ``` ### Customize checked value Use `checked-value` and `unchecked-value` to customize respective values. ```vue ``` ### Shape Switch can have square shape. ```vue ``` ### Customizing colors ```vue ``` ### Customizing Icon ```vue ``` ## API ### Switch Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | checked-value | `string \| boolean \| number` | `true` | Value of checked state. | | | default-value | `boolean` | `false` | Default value. | | | disabled | `boolean` | `false` | Whether to disable the switch. | | | loading | `boolean` | `false` | Whether to show loading state. | | | rail-style | `(info: { focused: boolean, checked: boolean }) => (CSSProperties \| string)` | `undefined` | Rail style generator. | | | round | `boolean` | `true` | Whether the switch has rounded corners. | | | rubber-band | `boolean` | `true` | Whether the switch button has rubber band effect. | 2.28.3 | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | The size of the switch. | | | spin-props | `{ strokeWidth?: number, stroke?: string, scale?: number, radius?: number }` | `undefined` | Loading icon properties. | 2.44.0 | | unchecked-value | `string \| boolean \| number` | `false` | Value of unchecked state. | | | value | `string \| number \| boolean \| undefined` | `undefined` | Value when being set manually. | | | on-update:value | `(value: boolean) => void` | `undefined` | Callback when the component's value changes. | | ### Switch Slots | Name | Parameters | Description | Version | | --- | --- | --- | --- | | checked | `()` | Content when the switch is checked. | | | checked-icon | `()` | Icon of switch button when checked. | 2.25.3 | | icon | `()` | Icon of switch button. | 2.25.3 | | unchecked | `()` | Content when the switch is unchecked. | | | unchecked-icon | `()` | Icon of switch button when unchecked. | 2.25.3 | --- # Time Picker Like a digital clock. ## Demos ### Basic ```vue ``` ### Confirm ```vue ``` ### Size The Time Picker can be a `small`, `medium` or `large` size. ```vue ``` ### Disable time If you can't stop time, at least disable it. ```vue ``` ### Step time Pass a number as an incremental step, or use an array to specify the values you want to show. If inputs do not adhere to these parameters, an invalid status will be shown (strikethrough text). ```vue ``` ### Format ```vue ``` ### Actions ```vue ``` ### 12 hours ```vue ``` ### Use formatted value Use `formatted-value` to control formatted value. ```vue ``` ### Focus & blur manually ```vue ``` ### Validation status Validation status can be applied outside form. ```vue ``` ### Time zone ```vue ``` ## API ### TimePicker Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | actions | `Array<'clear' \| 'now' \| 'confirm'> \| null` | `['now', 'confirm']` | Operations supported by the Time Picker. | `'clear'` 2.37.0 | | clearable | `boolean` | `false` | Whether the value is clearable. | | | default-value | `number \| null` | `null` | Default value. | | | default-formatted-value | `number \| null` | `undefined` | Default formatted value. | 2.24.0 | | disabled | `boolean` | `false` | Disabled state. | | | format | `string` | `'HH:mm:ss'` | Time format. For possible formats see [date-fns.org](https://date-fns.org/v2.23.0/docs/format). | | | formatted-value | `string \| null` | `undefined` | Formatted value. | 2.24.0 | | hours | `number \| number[]` | `undefined` | The array of hours that can be selected. If a number, it'll be converted into an array of numbers using that increment. | | | minutes | `number \| number[]` | `undefined` | The array of minutes that can be selected. If a number, it'll be converted into an array of numbers using that increment. | | | seconds | `number \| number[]` | `undefined` | The array of seconds that can be selected. If a number, it'll be converted into an array of numbers using that increment. | | | input-readonly | `boolean` | `false` | Readonly state (does not apply to touch devices). | | | is-hour-disabled | `(hour: number) => boolean` | `() => false` | Callback function for disabling hours. | | | is-minute-disabled | `(minute: number, hour: number \| null) => boolean` | `() => false` | Callback function for disabling minutes. When value is empty, `hour` is `null`. | | | is-second-disabled | `(second: number, minute: number \| null, hour: number \| null) => boolean` | `() => false` | Callback function for disabling seconds. When value is empty, `hour` and `minute` are `null`. | | | placeholder | `string` | `'Select Time'` | Placeholder. | | | placement | `'top-start' \| 'top' \| 'top-end' \| 'right-start' \| 'right' \| 'right-end' \| 'bottom-start' \| 'bottom' \| 'bottom-end' \| 'left-start' \| 'left' \| 'left-end'` | `'bottom-start'` | Time picker panel's placement. | 2.25.0 | | show | `boolean` | `undefined` | Whether to show panel | 2.28.3 | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | Size. | | | status | `'success' \| 'warning' \| 'error'` | `undefined` | Validation status. | 2.27.0 | | time-zone | `string` | `undefined` | Time zone to be used to format the value. It follows [iana time zones](https://www.iana.org/time-zones). You can use `Intl.supportedValuesOf('timeZone')` to check supported values. | 2.30.0 | | to | `string \| HTMLElement \| false` | `body` | Container node of the menu. `false` will keep it not detached. | | | use-12-hours | `boolean` | `false` | Whether to use a 12-hour clock panel. | | | value | `number \| null` | `undefined` | Value when being set manually. | | | value-format | `string` | follows `format` | Format of formatted value. | 2.24.0 | | on-blur | `() => void` | `undefined` | Callback when the selection box loses focus. | | | on-clear | `() => void` | `undefined` | Callback when value is cleared. | 2.28.3 | | on-confirm | `(value: number \| null, formattedValue: string \| null) => void` | `undefined` | Callback when the click confirm button. | 2.28.3 | | on-focus | `() => void` | `undefined` | Callback when the selection box gets focus. | | | on-update:formatted-value | `(value: number \| null, timestampValue: number \| null) => void` | `undefined` | Callback when formatted value changes. | 2.24.0 | | on-update:show | `(show: boolean) => void` | `undefined` | Callback when panel shows & hides. | 2.28.3 | | on-update:value | `(value: number \| null, formattedValue: string \| null) => void` | `undefined` | Callback when the value changes. | `formattedValue` 2.24.0 | ### TimePicker Slots | Name | Parameters | Description | | ---- | ---------- | ----------- | | icon | `()` | Custom icon | ### TimePicker Methods | Name | Type | Description | Version | | ----- | ------------ | ----------- | ------- | | focus | `() => void` | Focus. | 2.24.2 | | blur | `() => void` | Blur. | 2.24.2 | --- # Transfer A more efficient transfer. If you want to use original transfer, please refer to [Legacy Transfer](https://www.naiveui.com/en-US/components/legacy-transfer.md). Please note that the legacy transfer will be removed in the next major version. It's not recommended to to use it. ## Demos ### Basic Basic example of the Transfer component. If you have tons of data, see below for virtualized list. ```vue ``` ### Large data ```vue ``` ### Filterable ```vue ``` ### Custom label Transfer can be applied for many scenarios. ```vue ``` ### Custom source list ```vue ``` ## API ### Transfer Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | clear-text | `string` | `undefined` | Text of clear button. | 2.35.0 | | default-value | `Array \| null` | `null` | Default value. | 2.32.0 | | disabled | `boolean` | `true` | Disabled state. | 2.32.0 | | filter | `(pattern: string, option: TransferOption, from: 'source' \| 'target') => boolean` | A basic label string match function. | 2.32.0, `from` 2.32.2 | | options | `TransferOption[]` | `[]` | For configuration options, see the TransferOption Type below. | 2.32.0 | | render-source-label | `(props: { option: TransferOption }) => VNodeChild` | `undefined` | Customize source label rendering. | 2.32.0 | | render-target-label | `(props: { option: TransferOption }) => VNodeChild` | `undefined` | Customize target label rendering. | 2.32.0 | | render-source-list | `(props: { onCheck: (checkedValueList: Array) => void, checkedOptions: TransferOption[], pattern: string }) => VNodeChild` | `undefined` | Customize source list rendering. | 2.32.0 | | render-target-list | `(props: { onCheck: (checkedValueList: Array) => void, checkedOptions: TransferOption[], pattern: string }) => VNodeChild` | `undefined` | Customize target list rendering. | 2.33.4 | | select-all-text | `string` | `undefined` | Text of select all button. | 2.35.0 | | show-selected | `boolean` | `true` | Whether to show selected options in the source list. | 2.34.0 | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | Size. | 2.32.0 | | source-filterable | `boolean` | `false` | The source filterable state. | 2.32.2 | | source-filter-placeholder | `string` | `undefined` | Placeholder for the source items search box. | 2.32.0 | | source-title | `string \| (() => VNodeChild)` | `undefined` | Source items title. | 2.32.0, Render function since 2.40.0 | | target-filterable | `boolean` | `false` | The target filterable state. | 2.32.2 | | target-filter-placeholder | `string` | `undefined` | Placeholder for the target items search box. | 2.32.0 | | target-title | `string \| (() => VNodeChild)` | `undefined` | Target items title. | 2.32.0, Render function since 2.40.0 | | value | `Array \| null` | `undefined` | Value when being set manually. | 2.32.0 | | on-update:value | `(value: Array) => void` | `undefined` | Callback when the value changes. | 2.32.0 | | virtual-scroll | `boolean` | `false` | Enable virtual scrolling. | 2.32.0 | #### TransferOption Type | Property | Type | Description | | -------- | ------------------ | ------------------------------ | | label | `string` | The option's label to display. | | value | `string \| number` | The option's unique value. | | disabled | `boolean` | The option's disabled state. | --- # Tree Select It's said that 99% of the people can't distinguish the `TreeSelect` component from the `Cascader` component. ## Demos ### Basic ```vue ``` ### Customize fields You can also target difference label and key properties of the objects you are using as nodes. ```vue ``` ### Multiple ```vue ``` ### Use checkbox If you want to have the same effect of this demo, you will need `checkable`, `cascade` and `multiple` properties. ```vue ``` ### Set check strategy Set the way to display selected nodes when parents and children are selected. `all` will display both the parent and the children when all the children are selected. `parent` will only show the parent option if all of the children are selected. `child` will only ever show leaf nodes (nodes with no children). ```vue ``` ### Show Line Use `show-line` prop to display tree connecting lines. ```vue ``` ### Filterable ```vue ``` ### Action slot Maybe you need to use this slot in the tree selection menu. ```vue ``` ### Async loading Use `on-load` callback to load data. When loading async, all nodes with `isLeaf` set to `false` and `chilren`'s type is not `Array` will be reckon as unloaded nodes. ```vue ``` ### Validation status Validation status can be applied outside form. ```vue ``` ### File picker Use `override-default-node-click-behavior` to simulate a file picker (folder is not selectable). ```vue ``` ## API ### TreeSelect Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | allow-checking-not-loaded | `boolean` | `false` | Whether to allow cascade checking on not loaded nodes. If you want to use this, you should know the `value` may be incomplete. Also, you should aware about the consistency bewteen naive's checking logic and your backend's checking logic, especially when there are disabled nodes. | 2.28.1 | | cascade | `boolean` | `false` | Whether to link the selection of parent and child nodes. | | | checkable | `boolean` | `false` | Whether to use a checkbox to select values. | | | check-strategy | `string` | `'all'` | How to display selected nodes when parents and children are selected. | | | children-field | `string` | `'children'` | The children property to use for `TreeSelectOption`'s. | | | clearable | `boolean` | `false` | Whether the selection is clearable. | | | clear-filter-after-select | `boolean` | `true` | When multiple and filter is true, whether to clear filter keyword after select an option. | 2.25.3 | | consistent-menu-width | `boolean` | `true` | Force the widths of selection input and menu to be equal. \*This will disable virtual scrolling. | | | default-value | `string \| number \| Array \| null` | `null` | Selected key (or keys when `multiple`) by default. | | | default-expand-all | `boolean` | `false` | Expand all nodes by default. | | | default-expanded-keys | `Array` | `[]` | Expand specific keys by default. | | | disabled | `boolean` | `false` | Disabled state. | | | ellipsis-tag-popover-props | `PopoverProps` | `undefined` | `popover` props of the preview ellipsis tag. | 2.37.0 | | expanded-keys | `Array` | `undefined` | Collection of expanded keys. | | | indent | `number` | `24` | Indent of per level of the tree. | 2.41.1 | | indeterminate-keys | `Array` | `undefined` | Indeterminate keys of the tree. | | | filterable | `boolean` | `false` | Whether to show a filter. | | | filter | `(pattern: string, option: TreeSelectOption) => boolean` | - | Filter function. | | | get-children | `(option: any) => unknown` | `undefined` | Get children of the option. | 2.38.1 | | key-field | `string` | `'key'` | The key field used for `TreeSelectOption`. | | | label-field | `string` | `'label'` | The label field used for `TreeSelectOption`. | | | disabled-field | `string` | `'disabled'` | The disabled field used for `TreeSelectOption`. | 2.32.2 | | loading | `boolean` | `false` | Whether it's loading. | 2.28.3 | | max-tag-count | `number \| 'responsive'` | `undefined` | Maximum number of selected options to show before the list is truncated. `'responsive'` will keep all of the selected options in one row. | | | menu-props | `HTMLAttributes` | `undefined` | The menu's dom props. | 2.22.0 | | multiple | `boolean` | `false` | Allow selecting multiple options. | | | node-props | `(info: { option: TreeSelectOption }) => HTMLAttributes` | `undefined` | HTML attributes of node. | 2.30.7 | | options | `TreeSelectOption[]` | `[]` | Options. | | | override-default-node-click-behavior | `(info: { option: TreeSelectOption }) => 'toggleExpand' \| 'toggleSelect' \| 'toggleCheck' \| 'default' \| 'none'` | `undefined` | Override default node click behavior. | 2.37.0 | | placeholder | `string` | `'Please Select'` | Placeholder. | | | placement | `'top-start' \| 'top' \| 'top-end' \| 'right-start' \| 'right' \| 'right-end' \| 'bottom-start' \| 'bottom' \| 'bottom-end' \| 'left-start' \| 'left' \| 'left-end'` | `'bottom-start'` | Tree select menu's placement. | 2.25.0 | | render-label | `(info: { option: TreeSelectOption, checked: boolean, selected: boolean }) => VNodeChild` | `undefined` | Render function of all the options' label. | 2.30.7 | | render-prefix | `(info: { option: TreeSelectOption, checked: boolean, selected: boolean }) => VNodeChild` | `undefined` | Render function of all the options' prefix. | 2.30.7 | | render-suffix | `(info: { option: TreeSelectOption, checked: boolean, selected: boolean }) => VNodeChild` | `undefined` | Render function of all the options' suffix. | 2.30.7 | | render-switcher-icon | `() => VNodeChild` | `undefined` | Render function of option switcher icon. | 2.30.7 | | render-tag | `(props: { option: TreeSelectOption, handleClose: () => void }) => VNodeChild` | `undefined` | Render function for each option tag. | 2.30.7 | | separator | `string` | `' / '` | Option value separator. | | | show-line | `boolean` | `false` | Whether to display tree connecting lines. | 2.44.0 | | show-path | `boolean` | `false` | Whether to also show the hierarchy of selected nodes in the label. | | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | Component size. | | | status | `'success' \| 'warning' \| 'error'` | `undefined` | Validation status. | 2.27.0 | | to | `string \| HTMLElement \| false` | `body` | Container node of the menu. `false` will keep it not detached. | | | value | `string \| number \| Array \| null>` | `undefined` | Selected key (or keys when multiple). | | | virtual-scroll | `boolean` | `true` | Whether to enable virtual scrolling. | | | watch-props | `Array<'defaultCheckedKeys' \| 'defaultSelectedKeys' \|'defaultExpandedKeys'>` | `undefined` | Default prop names that needed to be watched. Components will be updated after the prop is changed. Note: the `watch-props` itself is not reactive. | 2.36.0 | | on-blur | `(e: FocusEvent) => void` | `undefined` | Callback on blur. | | | on-focus | `(e: FocusEvent) => void` | `undefined` | Callback on focus. | | | on-load | `(node: TreeSelectOption) => Promise` | `undefined` | Callback function for asynchronously loading data. | 2.27.0 | | on-update:expanded-keys | `(value: Array, meta: { node: TreeOption \| null, action: 'expand' \| 'collapse' \| 'filter' }) => void` | `undefined` | Callback on expanded keys updated. | `meta` 2.34.0 | | on-update:indeterminate-keys | `(keys: Array) => void` | `undefined` | Callback function on indeterminate options changing. | | | on-update:value | `(value: string \| number \| Array \| null, option: TreeSelectOption \| null \| Array, meta: { node: TreeOption \| null, action: 'select' \| 'unselect' \| 'delete' \| 'clear' }) => void) => void` | `undefined` | Callback on value updated. | | ### TreeSelectOption Properties | Name | Type | Description | Version | | --- | --- | --- | --- | | key | `string \| number` | Unique option key. The field used can be set using `key-field`. | | | label | `string` | Displayed content of the option. The field used can be set using `label-field`. | | | children? | `TreeSelectOption[]` | Child options of the option. The field used can be set using `children-field` | | | disabled? | `boolean` | Option disabled state. | | | isLeaf? | `boolean` | Whether the node is leaf. Required in async mode. | 2.27.0 | ### TreeSelect Slots | Name | Parameters | Description | Version | | ------ | ---------- | -------------------------------------- | ------- | | header | `()` | Header menu slot. | 2.40.0 | | action | `()` | Options menu slot. | 2.22.0 | | arrow | `()` | Arrow icon of trigger. | 2.30.4 | | empty | `()` | Empty state slot for the options menu. | 2.22.0 | ### TreeSelect Methods | Name | Type | Description | Version | | --- | --- | --- | --- | | blur | `() => void` | Blur. | 2.34.0 | | blurInput | `() => void` | Input blur. | 2.35.0 | | focus | `() => void` | Focus. | 2.34.0s | | focusInput | `() => void` | Input focus. | 2.35.0 | | getCheckedData | `() => { keys: Array, options: Array }` | Get checked data. | 2.34.0 | | getIndeterminateData | `() => { keys: Array, options: Array }` | Get indeterminate data. | 2.34.0 | --- # Upload If latency didn't matter, I'd just fill trucks with hard disks. ## Demos ### Basic ```vue ``` ### Drag to upload You can set `directory-dnd` to `true` to make directory drag and drop available. ```vue ``` ### Uncontrolled manually submit You can use a `ref` to get a handle on files uploaded, and the `submit` method to submit them when you're ready. ```vue ``` ### Autogenerated file list This example is just a joke. ```vue ``` ### Change file on finish You can change a file's properties after its upload has finished. ```vue ``` ### Default file list ```vue ``` ### Before upload hook Use `before-upload` to perform a function before the upload starts (e.g. cancel the upload). ```vue ``` ### Thumbnail file list Thumbnails can be created using your own custom method via the `create-thumbnail-url` property. ```vue ``` ### Pictures wall By default, this will use Naive UI's internal preview component. You can also use `on-preview` to customize what to do when previewing a file. ```vue ``` ### Custom request User `custom-request` to customize upload request. ```vue ``` ### Custom download Use `custom-download` to customize file downloading. By default, naive-ui uses native download logic (which initiates downloading by perform a click on an `` element with correspoding URL). However, you may want to preform custom download logic for example in a cross origin downloading process. ```vue ``` ### Split trigger and list Note: `n-upload-trigger` and `n-upload-file-list` must be children of ``. ```vue ``` ### Download when finished set `show-download-button` to show download button. set `on-download` to provide a handler function when download button clicked. ```vue ``` ## API ### Upload Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | abstract | `boolean` | `false` | Whether or not DOM wrapping does not exist. Not supported for `image-card` type. | | | accept | `string` | `undefined` | The accept type of upload. See [accept](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept). | | | action | `string` | `undefined` | The URL to submit data to. | | | always-show-actions | `boolean` | `false` | Always show the action buttons (remove, download, retry, preview) on each file item. When `false`, they only appear on hover. | 2.45.0 | | create-thumbnail-url | `(file: File \| null, fileInfo: UploadSettledFileInfo) => (Promise \| string \| undefined)` | `undefined` | Customize file thumbnails. If `undefined` is returned, the file would use default thumbnail display logic. | `fileInfo` 2.34.0 | | custom-request | `(options: UploadCustomRequestOptions) => void` | `undefined` | Customize upload request. For types, see [UploadCustomRequestOptions](#UploadCustomRequestOptions-Type) | | | custom-download | `(file: FileInfo) => void` | `undefined` | Customize download request | 2.41.1 | | data | `Object \| ({ file: UploadFileInfo }) => Object` | `undefined` | The additional fileds data of HTTP request's form data. | | | default-file-list | `Array` | `[]` | The default file list in uncontrolled manner. | | | default-upload | `boolean` | `true` | If file uploaded immediately after file is selected. | | | directory | `boolean` | `false` | Whether to allow directory upload. (In open file dialog only directory can be selected) | 2.28.3 | | directory-dnd | `boolean` | `false` | Whether to allow directory drag and drop. (If it's not set, it will follow `directory` prop by default.) | 2.28.3 | | disabled | `boolean` | `false` | Whether to disable the upload. | | | file-list-class | `string` | `undefined` | The class of file list area | 2.36.0 | | file-list-style | `Object` | `undefined` | The style of file list area | | | file-list | `Array` | `undefined` | The file list of component. If set, the component will work in controlled manner. | | | headers | `Object \| ({ file: UploadFileInfo }) => Object` | `undefined` | The additional HTTP Headers of request. | | | input-props | `InputHTMLAttributes` | `undefined` | Attributes of file input. | 2.24.2 | | image-group-props | `ImageGroupProps` | `undefined` | Props of `n-image` inside upload. See [ImageGroup Props](https://www.naiveui.com/en-US/components/image.md#ImageGroup-Props). | 2.24.0 | | is-error-state | `(xhr: XMLHttpRequest) => boolean` | `undefined` | Check if response is error state. | 2.29.1 | | list-type | `string` | `'text'` | Built-in styles for file lists, `text`, `image` and `image-card`. | | | max | `number` | `undefined` | Uploaded files limit. | | | method | `string` | `'POST'` | The HTTP request method. | | | multiple | `boolean` | `false` | Allow multiple files to be selected. | | | name | `string` | `'file'` | The field name for the file(s) in the HTTP request's form data. | | | render-icon | `(file: UploadSettledFileInfo) => VNodeChild` | `undefined` | Render function of file icon. It only works when `list-type="image"` or `list-type="image-card"`. | 2.34.0 | | response-type | `'' \| 'arraybuffer' \| 'blob' \| 'document' \| 'json' \| 'text'` | `''` | Response type of `XMLHttpRequest` used by `n-upload` | 2.33.3 | | should-use-thumbnail-url | `(file: UploadSettledFileInfo) => boolean` | A function that only returns `true` for image typed file. | A function that determines whether to show thumbnail for the file. It only works when `list-type="image"` or `list-type="image-card"`. | 2.34.0 | | show-cancel-button | `boolean` | `true` | Show a cancel button (while uploading). Use the `on-remove` callback for this event. | | | show-download-button | `boolean` | `false` | Show a download button (after upload is finished). | | | show-file-list | `boolean` | `true` | Show a file list. | | | show-preview-button | `boolean` | `true` | Show a preview button (when `list-type` is `image-card`). Use the `on-preview` callback for this event. | | | show-remove-button | `boolean` | `true` | Show a remove button (after upload completed). Use the `on-remove` callback for this event. | | | show-retry-button | `boolean` | `true` | Show a retry button (for a failed upload). | | | show-trigger | `boolean` | `true` | Show upload trigger. | 2.21.5 | | trigger-class | `string` | `undefined` | Class of trigger area. | 2.36.0 | | trigger-style | `Object \| string` | `undefined` | Style of trigger area. | 2.29.1 | | with-credentials | `boolean` | `false` | Any credentials to be sent with the request (e.g. cookie). | | | on-change | `(options: { file: UploadFileInfo, fileList: Array, event?: Event }) => void` | `undefined` | Uploaded file(s) status change callback. | | | on-error | `(options: { file: UploadFileInfo, event?: ProgressEvent }) => UploadFileInfo \| void` | `undefined` | Upload failed callback. | 2.24.0 | | on-finish | `(options: { file: UploadFileInfo, event?: Event }) => UploadFileInfo \| undefined` | `({ file }) => file` | Upload finished callback. You can intercept and even modify the uploaded `UploadFileInfo`. Note: file will be null in next event-loop | | | on-before-upload | `(options: { file: UploadFileInfo, fileList: Array }) => (Promise \| boolean \| void)` | `true` | Upload ready to start callback. Returning `false`, a promise resolved with `false`, or a rejected promise will cancel the upload. | | | on-download | `(file: FileInfo) => Promise \| boolean \| any` | `undefined` | Callback for clicking download buttons. Returning `false`, `Promise resolve false`, `Promise rejected` will cancel the download. | | | on-preview | `(file: FileInfo, detail: { event: MouseEvent }) => void` | `undefined` | Callback for clicking file links or preview buttons. You can use `preventDefault` to prevent default anchor link open behavior. | `detail.event` 2.39.0 | | on-remove | `(options: { file: UploadFileInfo, fileList: Array, index: number }) => Promise \| boolean \| any` | `() => true` | File removed callback. Returning `false`, a promise resolved with `false`, or a rejected promise will cancel this removal. | `index` 2.38.2 | | on-retry | `(options: { file: UploadFileInfo }) => (Promise \| boolean \| void)` | `undefined` | Click retry callback function. Returning `false`, a promise resolved with `false`, or a rejected promise will cancel the retry. | 2.40.0 | | on-update:file-list | `(fileList: UploadFileInfo[]) => void` | `undefined` | Callback function triggered on file-list changes. | | #### UploadFileInfo Type | Property | Type | Description | Version | | --- | --- | --- | --- | | id | `string \| number` | Unique file ID. Please note that do not change it, if you need to save some corresponding data, you can use a Map object outside component. | | | name | `string` | Filename. | | | status | `'pending' \| 'uploading' \| 'error' \| 'finished' \| 'removed'` | The status of file. | | | batchId? | `string \| null` | Batch id of uploaded file. The files selected in a same upload batch will have same `batchId`. | 2.28.3 | | file? | `File \| null` | The object of the file stored in the browser. | | | fullPath? | `string \| null` | Relative path of uploaded file. | 2.28.3 | | percentage? | `number` | The progress percentage of the file being uploaded. | | | thumbnailUrl? | `string \| null` | Thumbnail URL. | | | type? | `string \| null` | MIME type. | | | url? | `string \| null` | File URL. | | ### UploadTrigger Props | Name | Type | Default | Description | | -------- | --------- | ------- | ------------------------------------------ | | abstract | `boolean` | `false` | Whether or not to use the `abstract` mode. | #### UploadCustomRequestOptions Type ```__ts interface UploadCustomRequestOptions { file: FileInfo action?: string data?: | Record | (({ file }: { file: FileInfo }) => Record) withCredentials?: boolean headers?: | Record | (({ file }: { file: FileInfo }) => Record) onProgress: (e: { percent: number }) => void onFinish: () => void onError: () => void } ``` ### Upload Methods | Name | Type | Description | Version | | --- | --- | --- | --- | | clear | `() => void` | Clear current upload list. | 2.24.2 | | openOpenFileDialog | `() => void` | Open the file dialog window. | | | submit | `(options?: { fileId?: string, retry?: boolean })` | Submit all files with pending status. | `retry`: `2.44.0` | ### Upload Slots | Name | Parameters | Description | | ------- | ---------- | -------------------------- | | default | `()` | The content of the upload. | ### UploadDragger Slots | Name | Parameters | Description | | --- | --- | --- | | default | `()` | The placeholder of the upload dragger; For an example see [Drag to Upload Demo](#drag.vue). | ### UploadTrigger Slots | Name | Parameters | Description | | --- | --- | --- | | default | `(options: { handleClick: () => void, handleDragOver: (e: DragEvent) => void, handleDragEnter: (e: DragEvent) => void, handleDragLeave: (e: DragEvent) => void, handleDrop: (e: DragEvent) => void})` | `handleClick` is the click upload function, `handleDrop` is the drag and drop upload function, `handleDragEnter`, `handleDragOver` and `handleDragLeave` are the drag and drop event functions. | ### Others 1. `uploadDownload`, with type of `(url: string, name: string | undefined): void`, you can import the method directly from naive-ui. --- # Calendar How time flies. ## Demos ### Basic A basic calendar. ```vue ``` ## API ### Calendar Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | default-value | `number` | `null` | Default selected date's timestamp. | | | is-date-disabled | `(timestamp: number) => boolean` | `undefined` | Validator of the date. | | | value | `number \| null` | `undefined` | Selected date's timestamp. | | | on-panel-change | `(info: { year: number, month: number })` | `undefined` | Callback on panel content is changed. | 2.24.0 | | on-update:value | `(timestamp: number, info: { year: number, month: number, date: number }) => void` | `undefined` | Callback on date is selected. `month` starts from 1. | | ## Calendar Slots | Name | Parameters | Description | Version | | --- | --- | --- | --- | | default | `({ year: number, month: number, date: number })` | Content to be rendered in each date. | | | header | `(props: { year: number, month: number })` | Header of the calendar. `month` starts from 1. | 2.29.1 | --- # Countdown A second is passed after a second has passed. ## Demos ### Basic A countdown string. ```vue ``` ### Precision 🧐🧐🧐 ```vue ``` ### Customizing countdown Do whatever you want. ```vue ``` ### Reset ```vue ``` ## API ### Countdown Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | active | `boolean` | `true` | Whether countdown is active. | 2.23.2 | | duration | `number` | `0` | The duration of the countdown (unit is millisecond). Not reactive. | 2.23.2 | | precision | `0 \| 1 \| 2 \| 3` | `0` | The precision of the second. | 2.23.2 | | render | `(props: { hours: number, minutes: number, seconds: number, milliseconds: number }) => VNodeChild` | `undefined` | Time's render function | 2.23.2 | | on-finish | `() => void` | `undefined` | The callback on countdown is finished. | 2.23.2 | ### Countdown Methods | Name | Type | Description | Version | | ----- | ------------ | ---------------- | ------- | | reset | `() => void` | Reset countdown. | 2.31.0 | --- # Code ## Prequisites > **Note** > > Due to package size, Naive UI doesn't include highlight.js. If you want to use Code, make sure you have set highlightjs before using it. The following code shows how to set hljs of Code. Importing highlight.js on demand is recommonded, because it can significantly reduce bundle size of your app. ```html ``` ## Demos ### Basic For example, JavaScript, Python and C++. ```vue ``` ### Inline For example, JavaScript. ```vue ``` ### Soft wrap Code can wrap content if it overflows. ```vue ``` ### Line numbers It can show line numbers in the code block. ```vue ``` ## API ### Code Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | code | `string` | `''` | Incoming code string. | | | hljs | `Object` | `undefined` | If you want to set hljs locally, pass it using this prop. | | | inline | `boolean` | `false` | Whether the code is displayed as inline. | | | language | `string` | `undefined` | Code language in highlightjs. | | | show-line-numbers | `boolean` | `false` | Whether to show line numbers. Won't work if `inline` or `word-wrap` is `true`. | 2.32.0 | | trim | `boolean` | `true` | Whether to display trimmed code. | | | word-wrap | `boolean` | `false` | Whether to display word-wrapped code. | 2.24.0 | --- # Data Table DataTable is used to displays rows of structured data. > **Caveat** > > - Each item of the array passing in the `data` prop represents a row of rendered data, and each row of data must have a unique `key`, otherwise the `row-key` prop must be specified on the table. > - In non-async mode, page count is determined by data's count. Even if you pass a `page-count` in, it won't change data table's displayed page count. If you want it behaves in this way, you should set `remote` prop. > - If you want to use the data returned by the server for display, paging, filtering, sorting, please refer to [Async](#ajax-usage.vue). ## Demos ### Basic usage ```vue ``` ### Empty ```vue ``` ### Unbordered & no row divider & no column divider ```vue ``` ### Size ```vue ``` ### Custom row props If you want to add attr or event handlers to a row, use `row-props` prop. ```vue ``` ### Merge cell Set colspan and rowspan by setting `colSpan` and `rowSpan` of column object. Set colspan in header by setting `titleColSpan` of column object. ```vue ``` ### Uncontrolled filter and sorter ```vue ``` ### Filter page state Set `pagination-behavior-on-filter` to control the behavior (whether to stay at current page of return to the first page) on filter state changed. If table stays on the current page and the total amount of filtered data cannot reach the current page, the last page of data would be shown. ```vue ``` ### Multiple column sorting Set `multiple` and `compare` on `sorter` to enable multiple column sorting. `multiple` is the priority of sorting (larger value means higher priority). ```vue ``` ### Custom sorter ```vue ``` ### Column draggable Only support leaf nodes. ```vue ``` ### Selection Rows can be selectable by making first column's type as `selection`. ```vue ``` ### Single selection Set `multiple: false` to make the column of `type='selection` a single selection mode. ```vue ``` ### Custom selection menu Set `options` on a selection type column to create selection dropdown near header checkbox. ```vue ``` ### Grouped header Note: If you want grouped header to be fixed, you need to set width of all fixed columns, includes columns with `children`. If not it may not display normally. ```vue ``` ### Controlled pagination ```vue ``` ### Controlled filter ```vue ``` ### Controlled sorter If one of the column objects' `sortOrder` is set to `'ascend'`, `'descend'` or `false`. The sorting behavior the table will be in a controlled manner. If multiple columns' `sortOrder` are set to `'ascend'` or `'descend'`, only first column of them will be applied. ```vue ``` ### Controlled multi-column sorting If column object's `sortOrder` is set to `'ascend'`, `'descend'` or `false`, the data table would be in controlled state. If you only want UI to display multiple sort state, you can leave `compare` empty. ```vue ``` ### Fixed header Display large amounts of data in scrollable view by set `max-height`. ```vue ``` ### Fixed header and column Note that: If you have set fixed column, you should also set `scroll-x`. ```vue ``` ### Summary Use `summary` prop to render summary. ```vue ``` ### Ellipsis Ellipsize cell content via setting `column.ellipsis`. ```vue ``` ### Ellipsis with tooltip Set `column.ellipsis.tooltip` to make ellipsis have tooltip. `column.ellipsis` accepts the same props as `n-ellipsis`. ```vue ``` ### Expand rows Note that: Expanded rows are not included in the `index` of `render`. ```vue ``` ### Customized column header rendering ```vue ``` ### Custom style Column: Set `className` property on column object to assign a class name to a certain column. ```vue ``` ### Async ```vue ``` ### Large data **Tip: When `virtual-scroll` is `true`, `rowSpan` will not take effect.** ```vue ``` ### Large data (rows & cols) If you have a large amount of row and column data, such as thousands of rows and hundreds of columns, `naive-ui` provides horizontal + vertical virtual scrolling functionality. Due to the inherent complexity of horizontal virtual scrolling, the corresponding configuration can be quite complex, with most of the following content being necessary: 1. Configure `virtual-scroll` to enable vertical virtual scrolling. 2. Configure `virtual-scroll-x` to enable horizontal virtual scrolling: - Each column needs to have a `width` property configured. - Configure the `scroll-x` property, setting it to the total width of all columns. - Configure the `min-row-height` property, setting it to the minimum height of each row, where all rows must be larger than this value. - Configure the `height-for-row` property, which is used to set the height of each row (since only a portion of the cells in each row are always visible, this cannot be automatically calculated). If not configured, the height of each row will be set to `min-row-height`. 3. If needed, configure `virtual-scroll-header`. By default, the header will still be fully rendered to maintain compatibility. You can enable virtual rendering for the header with this configuration: - Configure the `header-height` property, setting it to the height of the header. The example below corresponds to a table with 1000 rows * 1000 columns. `naive-ui`'s table can easily support table data in the millions. You won't find this kind of functionality in many free component libraries. ```vue ``` ### Customize Icons You can customize filter & filter menu & sorter & expand icon. ```vue ``` ### Tree data Set `children` in row data to show tree data. If you want to use other key to get children, you can set another `children-key`. ```vue ``` ### Flex height If you want to set the overall height of the table, you can set the `flex-height` property. ```vue ``` ### Striped Using `striped` prop to make it easier to distinguish rows. ```vue ``` ### Simple Editable Table ```vue ``` ### Switchable Editable Table ```vue ``` ### Context menu Use `n-dropdown` to implement a context menu. ```vue ``` ### Async expand tree data Change data in `onLoad` prop. ```vue ``` ### Customized cell rendering You may use `render-cell` to customize empty state. ```vue ``` ### Export CSV You can use `downloadCsv` method to export data as CSV file. If default CSV generation logic can't fit your needs, for example, `title` uses render function, or you need to adjust data format for each cell, you can customize the exported header and cell data with `get-csv-header` and `get-csv-cell` props. ```vue ``` ## API ### DataTable Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | allow-checking-not-loaded | `boolean` | `false` | Whether to allow cascade checking on not loaded nodes. If you want to use this, you should know the `check-row-keys` may be incomplete. | 2.28.0 | | bordered | `boolean` | `true` | Whether to show border. | | | bottom-bordered | `boolean` | `true` | Whether to show bottom border. | | | checked-row-keys | `Array` | `undefined` | The keys of checked rows. | | | cascade | `boolean` | `true` | Whether to do cascade checking when using tree data. | | | children-key | `string` | `'children'` | The key of children data in tree data's data entity. | | | columns | `Array` | `[]` | Columns to display. | | | data | `Array` | `[]` | Data to display. | | | default-checked-row-keys | `Array` | `[]` | The key value selected by default. | | | default-expanded-row-keys | `Array` | `[]` | The key value of the expanded tree data by default | | | default-expand-all | `boolean` | `false` | Whether to expand all expandable rows. Can't be used with async expanding data. | 2.30.4 | | expanded-row-keys | `Array` | `undefined` | Expanded row keys. | | | filter-icon-popover-props | `PopoverProps` | `{ trigger: click, placement: bottom }` | Filter icon's Popover attribute of the button, See [Popover props](https://www.naiveui.com/en-US/components/popover.md#Popover-Props) | 2.39.0 | | flex-height | `boolean` | `false` | Whether to make table body's height auto fit table area height. Make it enabled will make `table-layout` always set to `'fixed'`. | | | get-csv-cell | `(value: any, row: object, col: DataTableBaseColumn) => string` | `undefined` | Get CSV's cell content. | 2.40.2 | | get-csv-header | `(cols: Array) => string` | `undefined` | Get CSV's header content. | 2.40.2 | | header-height | `number` | `28` | Header height value when `virtual-scroll-header` is enabled. | 2.40.0 | | height-for-row | `(rowData: object, index: number) => number` | `undefined` | Height configuration function for each row of the table. It must be used with `virtual-scroll-x`. If it's not configured, each rows height would be set to `min-row-height`. | 2.40.0 | | indent | `number` | `16` | Indent of row content when using tree data. | | | loading | `boolean` | `false` | Whether to display loading status. | | | max-height | `number \| string` | `undefined` | The max-height of the table content. Can be a CSS value. | | | min-height | `number \| string` | `undefined` | The min-height of the table content. Can be a CSS value. | | | min-row-height | `number` | `28` | Min row height of the table when `virtual-scroll` or `virtual-scroll-x` is enabled. Each row's height must be larger than its value. | 2.40.0 | | paginate-single-page | `boolean` | `true` | Whether show pagination data is less than one page. | 2.28.0 | | pagination | `false \| object` | `false` | See [Pagination props](https://www.naiveui.com/en-US/components/pagination.md#Pagination-Props) | | | pagination-behavior-on-filter | `'first' \| 'current'` | `'current'` | The behavior of pagination after filter state is changed. `'first'` means returning to first page on filter, `'current'` means keep at current page on filter. | 2.28.3 | | remote | `boolean` | `false` | If data-table do automatic paging. You may set it to `true` in async usage. | | | render-cell | `(value: any, rowData: object, column: DataTableBaseColumn) => VNodeChild` | `undefined` | Render function of cell, it will be overwritten by columns' `render`. | 2.30.5 | | render-expand-icon | `({ expanded, rowData }: { expanded: boolean, rowData: object }) => VNodeChild` | `undefined` | Render function of expand icon. | 2.32.2, `expanded`: 2.34.4, `rowData`: `2.40.0` | | row-class-name | `string \| (rowData: object, rowIndex : number) => string` | `undefined` | Class name of each row. | | | row-key | `(rowData: object) => (number \| string)` | `undefined` | Generate the key of the row by row data (if you don't want to set the key). | | | row-props | `(rowData: object, rowIndex : number) => HTMLAttributes` | `undefined` | Customize row attributes. | | | scroll-x | `number \| string` | `undefined` | If columns are horizontal fixed, scroll-x need to be set. | | | scrollbar-props | `ScrollbarProps` | `undefined` | See [Scrollbar props](https://www.naiveui.com/en-US/components/scrollbar.md#Scrollbar-Props), the `on-scroll` attribute already exists in the `DataTable`, the `on-scroll` attribute does not take effect here. | | | single-column | `boolean` | `false` | Whether rows are not divided. If the prop is `true`, table cell has no `border-bottom`. | | | single-line | `boolean` | `true` | Whether columns are not divided. If the prop is `true`, table cell has no `border-right`. | | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | Table size. | | | spin-props | `{ strokeWidth?: number, stroke?: string, scale?: number, radius?: number }` | `undefined` | Table spin's props. | 2.34.0 | | sticky-expanded-rows | `boolean` | `false` | Expanded row content remains sticky. | 2.32.2 | | striped | `boolean` | `false` | Whether to show zebra stripes on rows. | | | summary | `DataTableCreateSummary` | `undefined` | Data of table summary row. For types, see [DataTableCreateSummary Type](#DataTableCreateSummary-Type). | | | summary-placement | `'top' \| 'bottom'` | `'bottom'` | Summary rows placement. | 2.33.3 | | table-layout | `'auto' \| 'fixed'` | `'auto'` | Style `table-layout` of the table. When `ellipsis` or `max-height` or `flex-height` are set, it will always be `'fixed'` regardless of what you set. | | | virtual-scroll | `boolean` | `false` | Whether to use virtual scrolling to deal with large data. Make sure `max-height` is set before using it. When `virtual-scroll` is `true`, `rowSpan` will not take effect. | | | virtual-scroll-header | `boolean` | `false` | Whether to use virtual scrolling in table header. If there are too many columns, you can enable the prop. You must configure `header-height` at the same time. Enabling the prop will disable header cells that cross columns & rows. | 2.40.0 | | virtual-scroll-x | `boolean` | `false` | Whether to use horizontal virtual scrolling in table body. If there are too many columns, you can enable the prop. Enabling the prop will disable body cells that cross columns & rows. If the prop is enabled, every column should have `width` prop configured and `virtual-scroll`, `scroll-x`, `min-row-height`, `height-for-row`, `virtual-scroll-header` (optional), `header-height` (optional) props should be configured at the same time. You can refer to [the example](#virtual-x.vue). | 2.40.0 | | on-load | `(rowData: object) => Promise` | `undefined` | Callback of async tree data expanding. | 2.27.0 | | on-scroll | `(e: Event) => void` | `undefined` | Callback of table body scrolling. | 2.29.1 | | on-update:checked-row-keys | `(keys: Array, rows: object[], meta: { row: object \| undefined, action: 'check' \| 'uncheck' \| 'checkAll' \| 'uncheckAll' }) => void` | `undefined` | The callback function triggered when the checked-row-keys value changes. | `rows` 2.30.5, `meta` 2.33.4 | | on-update:expanded-row-keys | `(keys: Array) => void` | `undefined` | The callback function triggered when the expanded-row-keys value changes. | | | on-update:filters | `(filters: DataTableFilterState, initiatorColumn: DataTableBaseColumn)` | `undefined` | The callback function triggered when the filters data changes. | | | on-update:page | `(page: number)` | `undefined` | Callback function triggered when the page changes. | | | on-update:page-size | `(pageSize: number) => void` | `undefined` | Callback function triggered when the page-size changes. | | | on-update:sorter | `(options: DataTableSortState \| DataTableSortState[] \| null) => void` | `undefined` | If the change column is sorted by multiple columns, will return `DataTableSortState[] \| null`, otherwise return `DataTableSortState \| null`. | | #### DataTableColumn Properties | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | align | `'left' \| 'right' \| 'center'` | `'left'` | Text align in column. | | | allowExport | `boolean` | `true` | Can the column exported | 2.40.0 | | cellProps | `(rowData: object, rowIndex: number) => object` | `undefined` | HTML attributes of the column's cell. | 2.27.0 | | children | `DataTableColumn[]` | `undefined` | Child nodes of a grouped column. | | | className | `string` | `undefined` | Class name of the column. | | | colSpan | `(rowData: object, rowIndex: number) => number` | `undefined` | The col span of the column cell. | | | customNextSortOrder | `(order: 'descend' \| 'ascend' \| false) => 'descend' \| 'ascend' \| false` | `undefined` | A function for custom next sorting status. | 2.43.0 | | defaultFilterOptionValue | `string \| number \| null` | `null` | The default active filter option value in uncontrolled manner. (works when not using multiple filters). | | | defaultFilterOptionValues | `Array` | `[]` | The default active filter option values in uncontrolled manner. (works when there are multiple filters). | | | defaultSortOrder | `'descend' \| 'ascend' \| false` | `false` | The default sort order of the table in uncontrolled manner. | | | disabled | `(rowData: object) => boolean` | `() => false` | Whether the row is checkable. | | | ellipsis | `boolean \| EllipsisProps` | `false` | Ellipsis options when content overflows. | | | ellipsis-component | `'ellipsis' \| 'performant-ellipsis'` | `'ellipsis'` | Component for rendering text ellipsis. It works when `ellipsis` is `EllipsisProps`. If it's `'ellipsis'`, table will use regular `n-ellipsis` component to render text ellipsis. If it's `'performant-ellipsis'`, table will use `n-performant-ellipsis` to render text ellipsis. In the later situation, rendering speed will be much faster but component inside table cell would be unmounted & remounted. | 2.35.0 | | expandable | `(rowData: object) => boolean` | `undefined` | Whethe the row is expandable. Only works when `type` is `'expand'`. | | | filter | `boolean \| (optionValue: string \| number, rowData: object) => boolean \| 'default'` | `false` | The filter of the column. If set to `true`, it will only display filter button on the column, which can be used in async status. | | | filterMode | `'and' \| 'or'` | `'or'` | The filter mode. | | | filterMultiple | `boolean` | `true` | Can the column filtered by multiple values. | | | filterOptionValue | `string \| number \| null` | `undefined` | The active filter option value in controlled manner. If not set, the filter of the column works in an uncontrolled manner. (works when not using multiple filters). | | | filterOptionValues | `Array \| null` | `undefined` | The active filter option values in controlled manner. If not set, the filter of the column works in an uncontrolled manner. (works when there are multiple filters). | | | filterOptions | `Array<{ label: string, value: string \| number}>` | `undefined` | Filter options. | | | fixed | `'left \| 'right' \| false` | `false` | Whether the column needs to be fixed. | | | key | `string \| number` | `undefined` | Unique key of this column, this is not repeatable. | | | maxWidth | `number \| string` | `undefined` | Max width of the column. Only works when `resizable` is `true`. | 2.33.4 | | minWidth | `number \| string` | `undefined` | Min width of the column. | 2.28.3 | | multiple | `boolean` | `true` | Whether to enable multiple selection mode. Only works when `type` is `'selection'`. | 2.31.0 | | options | `Array<'all' \| 'none' \| { label: string, key: string \| number, onSelect: (pageData: RowData[]) => void }>` | `undefined` | Options of custom selection. Only work with `type='selection'`. | | | render | `(rowData: object, rowIndex: number) => VNodeChild` | `undefined` | Render function of column row cell. | | | renderExpand | `(rowData: object, rowIndex: number) => VNodeChild` | `undefined` | Render function of the expand area. Only works when `type` is `'expand'`. | | | renderFilter | `(options: { active: boolean, show: boolean }) => VNodeChild` | `undefined` | Render function of column filter trigger. | | | renderFilterIcon | `(options: { active: boolean, show: boolean }) => VNodeChild` | `undefined` | Render function of column filter icon. | | | renderFilterMenu | `(actions: { hide: () => void }) => VNodeChild` | `undefined` | Render function of column filter menu. | | | renderSorter | `(options: { order: 'descend' \| 'ascend' \| false }) => VNodeChild` | `undefined` | Render function of column sorter trigger. | 2.24.2 | | renderSorterIcon | `(options: { order: 'descend' \| 'ascend' \| false }) => VNodeChild` | `undefined` | Render function of column sorter icon. | 2.24.2 | | resizable | `boolean` | `undefined` | Whethe the column width can be dragged. | 2.33.4 | | rowSpan | `(rowData: object, rowIndex: number) => number` | `undefined` | The row span of the cell. | | | sortOrder | `'descend' \| 'ascend' \| false` | `undefined` | The controlled sort order of the column. If multiple columns' sortOrder is set, the first one will affect. | | | sorter | `boolean \| function \| 'default'` | `false` | The sorter of the column. If set `'default'`, it will use a basic builtin compare function. If set to `true`, it will only display sort icon on the column, which can be used in async status. Otherwise it works like `Array.sort`'s compare function. | | | title | `string \| (() => VNodeChild)` | `undefined` | Column title, Can be a render function. | | | titleAlign | `'left' \| 'right' \| 'center'` | `null` | alignment of the table header. If omitted, the value of the above align attribute will be applied | 2.34.4 | | titleColSpan | `number` | `undefined` | The number of cells occupied by the title col. | | | tree | `boolean` | `false` | Whether to show tree data expand trigger in the column. | 2.28.3 | | type | `'selection' \| 'expand'` | `undefined` | Column type. | | | width | `number \| string` | `undefined` | Width of the column (**required and should be number** when fixed). | 2.24.0 (`string` type) | The following types can be imported from the package. #### DataTableSortState Type ```ts interface DataTableSortState { columnKey: string | number sorter: 'default' | function | boolean order: 'ascend' | 'descend' | false } ``` #### DataTableFilterState Type ```ts interface DataTableFilterState { [key: string]: Array | string | number | null | undefined } ``` #### DataTableCreateSummary Type ```ts type DataTableCreateSummary = (pageData: RowData[]) => | Array<{ [columnKey: string]: { value?: VNodeChild colSpan?: number rowSpan?: number } }> | { [columnKey: string]: { value?: VNodeChild colSpan?: number rowSpan?: number } } ``` ### DataTable Methods These methods can help you control table in an uncontrolled manner. However, it's not recommended to use them to implement some async operations. If async operations is needed, use table in a **controlled** manner. | Name | Type | Description | Version | | --- | --- | --- | --- | | clearFilters | `() => void` | Clear all filter state. | | | clearSorter | `() => void` | Clear all sort state. | | | downloadCsv | `(options?: { fileName?: string, keepOriginalData?: boolean }) => void` | Download CSV. | 2.37.0 | | getCurrentPageData | `() => RowData[]` | Get row data of the current page after filters, sorters and pagination are applied. | 2.45.0 | | getFilteredAndSortedData | `() => RowData[]` | Get all row data after filters and sorters are applied, excluding pagination. In `remote` mode, it is based on the current `data` prop only. | 2.45.0 | | filters | `(filters: DataTableFilterState \| null) => void` | Set the active filters of the table. | | | page | `(page: number) => void` | Manually set the page. | | | scrollTo | `DataTableScrollTo` | Scroll content. See [DataTableScrollTo Type](#DataTableScrollTo-Type). | 2.45.0 | | sort | `(columnKey: string \| number, order: 'ascend' \| 'descend' \| false) => void` | Set the sort state of the table. | | ### DataTable Slots | Name | Type | Description | Version | | ------- | ---- | ------------------------------------------------- | ------- | | empty | `()` | Custom description when data of table is empty. | | | loading | `()` | Custom description when data of table is loading. | 2.34.0 | #### DataTableScrollTo Type `scrollTo` delegates to virtual list when `virtual-scroll` is enabled, otherwise to the internal scrollbar. Available signatures by mode: | Signature | Virtual scroll | Non-virtual scroll | | --- | --- | --- | | `(x: number, y: number)` | Yes | Yes | | `{ left?, top?, behavior?, debounce? }` | Yes | Yes | | `{ position: 'top' \| 'bottom', behavior?, debounce? }` | Yes | Yes | | `{ index, behavior?, debounce? }` | Yes | No | | `{ key, behavior?, debounce? }` | Yes | No | | `{ el, behavior?, debounce? }` | No | Yes | | `{ index, elSize, behavior?, debounce? }` | No | Yes | When `virtual-scroll` is enabled, `scrollTo` still has some edge cases that are not fully handled. For example, using `behavior: 'smooth'` may have some issues; please refer to actual usage. --- # Descriptions Display items of content easily. ## Demos ### Basic ```vue ``` ### Columns You can adjust items per row by set column of descriptions. ```vue ``` ### Span You can set span for each item. ```vue ``` ### Label placement You can set label placement to `top` or `left`. ```vue ``` ### Bordered If there are too many multiple line fields, you can set it to `bordered`. ```vue ``` ### Size Description support `small`, `medium` and `large` size. ```vue ``` ## API ### Descriptions Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | bordered | `boolean` | `false` | Whether to display border. | | | column | `number` | `3` | Total columns. | | | content-class | `string` | `undefined` | Class of the item content. | 2.36.0 | | content-style | `Object \| string` | `undefined` | Style of the item content. | | | label-align | `'center' \| 'left' \| 'right'` | `'left'` | Label align. | | | label-placement | `'top' \| 'left'` | `'top'` | Label placement. | | | label-class | `string` | `undefined` | Class of the item label. | 2.36.0 | | label-style | `Object \| string` | `undefined` | Style of the item label. | | | separator | `string` | `':'` | Separator, only work when `label-placement` is `left` and `bordered` is `false`. | | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | Size of the description. | | | title | `string` | `undefined` | Title of the description. | | ### DescriptionItem Props | Name | Type | Default | Description | | --- | --- | --- | --- | | content-class | `string` | `undefined` | Class of the item content. | | content-style | `Object \| string` | `undefined` | Style of the item content. | | label | `string` | `undefined` | Label of the item. | | label-class | `string` | `undefined` | Class of the item label. | | label-style | `Object \| string` | `undefined` | Style of the item label. | | span | `number` | `1` | Column span of the item. | ### Descriptions Slots | Name | Parameters | Description | | ------- | ---------- | --------------- | | default | `()` | Content. | | header | `()` | Header content. | ### DescriptionItem Slots | Name | Parameters | Description | | ------- | ---------- | ------------- | | default | `()` | Item content. | | label | `()` | Item label. | --- # Empty Empty. ## Demos ### Basic ```vue ``` ### Icon Customize icon in empty. ```vue ``` ### Size Empty can be `tiny`, `small`, `medium`, `large` and `huge` size. ```vue ``` ## API ### Empty Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | description | `string` | `'No Data'` | Description of the empty. | | | show-description | `boolean` | `true` | Whether to show description of empty. | | | show-icon | `boolean` | `true` | Whether to show icon of empty. | | | size | `'tiny' \| 'small' \| 'medium' \| 'large' \| 'huge'` | `'medium'` | Empty's size. | 2.40.0 | ### Empty Slots | Name | Parameters | Description | | ------- | ---------- | ---------------------------- | | default | `()` | In place of description prop | | extra | `()` | Extra content. | | icon | `()` | Custom icon. | --- # Equation No one will think of that a component library should have this component. However a friend of me need this. > **Note** > > Due to package size, Naive UI doesn't include katex. If you want to use Equation, make sure you have setup katex before using it. The following code shows how to setup katex for Equation. ```html ``` ## Demos ### Basic usage ```vue ``` ### Using katex options ```vue ``` ## API ### Equation Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | katex | `object` | `undefined` | Katex | 2.34.0 | | katex-options | `object` | `undefined` | Katex options for the equation. | 2.34.0 | | value | `string` | `undefined` | Latex expression of the equation. | 2.34.0 | --- # Image Preview it. ## Demos ### Basic ```vue ``` ### Image group ```vue ``` ### Fail to load Use `fallback-src` to set an fallback image on error, or you can use `error` slot in the next demo. ```vue ``` ### Error slot You can use `error` slot to custom loading error display. ```vue ``` ### Disable preview You can use `preview-disabled` to disable preview. ```vue ``` ### Custom Toolbar You can customize the toolbar using `render-toolbar`. ```vue ``` ### Customizing toolbar by theme variables The default style of toolbar may not meet your demand, let's make some configuration. ```vue ``` ### Toolbar tooltip Some users doesn't know how keyboard operation works. You can show tooltip by setting `show-toolbar-tooltip`. ```vue ``` ### Lazy load Load the images only after they enter the viewport. There are two ways to use it: one is to use the `lazy` property alone, which will be set to the value of the [HTMLImageElement.loading](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/loading) property, and the other is to use `lazy` together with the `intersection-observer-options` configuration to implement lazy loading using the [IntersectionObserver](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver) API. ```vue ``` ### Previewed image props You can use `previewed-img-props` to set DOM attributes of previewed image. ```vue ``` ### Manually Open Preview Toggle big image preview by calling `showPreview` method. ```vue ``` ### Use Preview alone `n-image-preview` can be used alone。 ```vue ``` ### Multi-image preview Use `src-list` of `` to preview images without ``. ```vue ``` ## API ### Image Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | alt | `string` | `undefined` | Image alt information. | | | fallback-src | `string` | `undefined` | URL to show when the image fails to load. | | | height | `string \| number` | `undefined` | Image height. | | | img-props | `ImgHTMLAttributes` | `undefined` | The props of the img element inside the component. | | | lazy | `boolean` | `false` | Load image after it enters viewport. When used alone, it will be assigned the property value of [HTMLImageElement.loading](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/loading). Alternatively, it can be used in conjunction with the `intersection-observer-options` configuration to achieve lazy loading. | 2.30.5 | | intersection-observer-options | `{ root?: Element \| Document \| string \| null, rootMargin?: string, threshold?: number \| number[]; }` | `undefined` | Intersection observer's config to be applied when `lazy=true`. | 2.30.5 | | keep-drag-offset | `boolean` | `false` | Whether to keep the dragged offset of the previewed image after the mouse is released. By default the image snaps back to center (or to the viewport bounds when larger than the viewport). | 2.45.0 | | object-fit | `'fill' \| 'contain' \| 'cover' \| 'none' \| 'scale-down'` | `fill` | Object-fit type of the image in the container. | | | preview-src | `string` | `undefined` | Source of preview image. | | | preview-disabled | `boolean` | `false` | Whether clicking image preview is disabled. | | | previewed-img-props | `HTMLAttributes` | `undefined` | DOM attributes of img element in preview mode. | 2.34.0 | | render-toolbar | `(props: { nodes: { prev: VNode, next: VNode, rotateCounterclockwise: VNode, rotateClockwise: VNode, resizeToOriginalSize: VNode, zoomOut: VNode, zoomIn: VNode, download: VNode, close: VNode } }) => VNodeChild` | `undefined` | Toolbar rendering function. | `2.38.2` | | show-toolbar | `boolean` | `true` | Whether to show the bottom toolbar when the image enlarge. | | | show-toolbar-tooltip | `boolean` | `false` | Whether to show toolbar buttons' tooltip. | 2.24.0 | | src | `string` | `undefined` | Image source. | | | width | `string \| number` | `undefined` | Image width. | | | on-error | `(e: Event) => void` | `undefined` | Callback executed when the image fails to load. | | | on-load | `(e: Event) => void` | `undefined` | Callback executed after the image is loaded. | | ### ImageGroup Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | current | `number` | `undefined` | The subscript of the currently displayed image. | 2.43.0 | | default-current | `number` | `0` | The subscript of the default displayed image. | 2.43.0 | | default-show | `boolean` | `false` | Whether to show the preview big image by default. | 2.43.0 | | keep-drag-offset | `boolean` | `false` | Whether to keep the dragged offset of the previewed image after the mouse is released. By default the image snaps back to center (or to the viewport bounds when larger than the viewport). | 2.45.0 | | render-toolbar | `(props: { nodes: { prev: VNode, next: VNode, rotateCounterclockwise: VNode, rotateClockwise: VNode, resizeToOriginalSize: VNode, zoomOut: VNode, zoomIn: VNode, download: VNode, close: VNode } }) => VNodeChild` | `undefined` | Toolbar rendering function. | `2.38.2` | | show | `boolean` | `undefined` | Whether to the show preview big image. | 2.43.0 | | show-toolbar | `boolean` | `true` | Whether to show the bottom toolbar when the image enlarge. | | | show-toolbar-tooltip | `boolean` | `false` | Whether to show toolbar buttons' tooltip. | 2.24.0 | | src-list | `string[]` | `undefined` | Picture src list. | 2.43.0 | | on-preview-next | `() => void` | `undefined` | Click the callback on the next slide. | | on-preview-prev | `() => void` | `undefined` | Click the callback from the previous slide. | | | on-update:current | `(value: number) => void` | `undefined` | Callback on currently displayed image changes. | 2.43.0 | | on-update:show | `(value: boolean) => void` | `undefined` | Callback on show status changes. | 2.43.0 | ### ImagePreview Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | default-show | `boolean` | `false` | Whether to show the preview big image by default. | 2.43.0 | | keep-drag-offset | `boolean` | `false` | Whether to keep the dragged offset of the previewed image after the mouse is released. By default the image snaps back to center (or to the viewport bounds when larger than the viewport). | 2.45.0 | | render-toolbar | `(props: { nodes: { prev: VNode, next: VNode, rotateCounterclockwise: VNode, rotateClockwise: VNode, resizeToOriginalSize: VNode, zoomOut: VNode, zoomIn: VNode, download: VNode, close: VNode } }) => VNodeChild` | `undefined` | Toolbar rendering function. | 2.43.0 | | show | `boolean` | `undefined` | Whether to the show preview big image. | 2.43.0 | | show-toolbar | `boolean` | `true` | Whether to show the bottom toolbar when the image enlarge. | 2.43.0 | | show-toolbar-tooltip | `boolean` | `false` | Whether to show toolbar buttons' tooltip. | 2.43.0 | | src | `string` | `undefined` | Image source. | 2.43.0 | | on-close | `() => void` | `undefined` | Callback when close the preview of the image. | 2.43.0 | | on-update:show | `(value: boolean) => void` | `undefined` | Callback on show status changes. | 2.43.0 | ### Image Slots | Name | Parameters | Description | Version | | --- | --- | --- | --- | | error | `()` | The content when the image fails to load. | 2.40.2 | | placeholder | `()` | Placeholder shown when image is not loaded. | 2.30.5 | ### ImageGroup Slots | Name | Parameters | Description | | ------- | ---------- | --------------------------------------- | | default | `()` | The default content of the image group. | ### Image Methods | Name | Type | Description | Version | | ----------- | ------------ | ------------------------------------ | ------- | | showPreview | `() => void` | Show preview interface of the image. | 2.43.0 | --- # List It is hard to make it looks elegant. However things should be done. ## Demos ### Basic ```vue ``` ### Hoverable ```vue ``` ### Border List can be bordered or unbordered. ```vue ``` ## API ### List Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | bordered | `boolean` | `false` | Whether to show the border. | | | clickable | `boolean` | `false` | Whether item has clickable style. | 2.32.2 | | hoverable | `boolean` | `false` | Whether item has hoverable style. | 2.32.2 | | show-divider | `boolean` | `true` | Whether to show item divider. | 2.32.2 | ### List Slots | Name | Parameters | Description | | ------- | ---------- | ------------------------------------- | | default | `()` | The contents of the list. | | footer | `()` | Content at the bottom of the list. | | header | `()` | The contents of the head of the list. | ### ListItem Slots | Name | Parameters | Description | | ------- | ---------- | ----------------------------------- | | default | `()` | The contents of the list item. | | prefix | `()` | The first content of the list item. | | suffix | `()` | The end of the list item. | --- # Log If you have some logs to show, use log. > **Note** > > Due to package size, Naive UI doesn't include highlight.js. If you want highlight logs, make sure you have set highlightjs before using it. In highlight demo, we defined a language called `naive-log` which will highlight all the numbers of line. The following code shows how we defined it. If you want to know more about highlight.js, see [highlight.js](https://highlightjs.org/) and [highlight.js developer documentation](https://highlightjs.readthedocs.io/en/latest/index.html) ```html ``` ## Demos ### Rows Use `rows` to change the size of log. ```vue ``` ### Event Log has `require-more`, `reach-top` and `reach-bottom` event. Note that even if logs are scrolled to top or bottom, when you wheel to the same direction, `require-more` will still be triggered while `reach-xxx` will not. If you don't want to trigger handler when logs are at top or bottom. Use `reach-top` or `reach-bottom` instead. ```vue ``` ### Scroll You can easily make log scroll to top or bottom. Also you can make the scroll action silent (don't trigger events of Log in this scroll action). ```vue ``` ### Highlight Before you use highlight, see Note section of the page to make sure you won't miss messages that are important to make it work. ```vue ``` ### Loading ```vue ``` ### Scroll to latest Scroll to the latest when log is gradually increasing. ```vue ``` ## API ### Log Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | font-size | `number` | `14` | Font size. | | hljs | `Object` | `undefined` | If you want to set `hljs` locally, pass it using this prop. | | language | `string` | `undefined` | The language of the log in `highlightjs`. | | line-height | `number` | `1.25` | Line height. | | lines | `Array` | `undefined` | Display the log content by line. When the `log` parameter exists at the same time, the parameter is invalid. | | loading | `boolean` | `false` | Whether to show loading. | | log | `string` | `undefined` | The content of the log. | | rows | `number` | `15` | Log size. | | spin-props | `{ strokeWidth?: number, stroke?: string, scale?: number, radius?: number }` | `undefined` | Loading icon properties. | 2.44.0 | | trim | `boolean` | `false` | Whether to display the log after `trim`. | | on-require-more | `(from: 'top' \| 'bottom') => void` | `undefined` | Callback function for scroll loading log. | | on-reach-top | `() => void` | `undefined` | Scroll to the top callback function. | | on-reach-bottom | `() => void` | `undefined` | Scroll to the bottom callback function. | ### Log Methods | Name | Parameters | Description | | --- | --- | --- | | scrollTo | `(options: { top?: number, position?: 'top' \| 'bottom', silent?: boolean })` | Callback function for scroll event. | --- # Number Animation Tween the number. ## Demos ### Basic ```vue ``` ### Precision Use `precision` to set precision. ```vue ``` ### Separator The number is too large to count the digits. ```vue ``` ### I18n Use `locale` to set i18n language. Please note that, the feature uses `Intl` API. For compitability refers to [format](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/format) and [formatToParts](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/formatToParts). ```vue ``` ### Finish callback ```vue ``` ## API ### NumberAnimation Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | active | `boolean` | `true` | Whether to play the animation. | 2.23.2 | | duration | `number` | `3000` | The duration of | 2.23.2 | | from | `number` | `0` | Start value of the animation | 2.23.2 | | locale | `string` | Follows config provider. | Language of the number. | 2.24.2 | | precision | `number` | `0` | Decimal precision of the displayed value. | 2.23.2 | | show-separator | `boolean` | `false` | Whether to show separator. | 2.23.2 | | to | `number` | `undefined` | Target value. | 2.23.2 | | on-finish | `() => void` | `undefined` | The callback on animation is finished. | 2.31.0 | ### NumberAnimation Methods | Name | Parameters | Description | Version | | ---- | ---------- | ------------------- | ------- | | play | `()` | Play the animation. | 2.23.2 | --- # QR Code It is always only valid for a short time. Available since `2.36.0`. ## Demos ### Basic A basic QR Code. ```vue ``` ### Icon You can put some representative icons. ```vue ``` ### Size ```vue ``` ### Color Let the QR code no longer monotonous. ```vue ``` ### Error correction Use `error-correction-level` to set the error correction level. ```vue ``` ### Download Download two-dimensional code code implementation, you can also choose to right-click the picture to save it. ```vue ``` ### Customize Render Type Customize rendering output by setting `type`, providing two options: `canvas` and `svg`. ```vue ``` ## API ### QR Code Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | background-color | `string` | `'#FFF'` | QR code background color, Values need to be in `hex` format. | 2.36.0 | | color | `string` | `'#000'` | QR code color, Values need to be in `hex` format. | 2.36.0 | | error-correction-level | `'L'` \| `'M'` \| `'Q'` \| `'H'` | `'M'` | QR code error correction level. | 2.36.0 | | icon-border-radius | `number` | `4` | Icon background's border-radius | 2.36.0 | | icon-background-color | `string` | `'#FFF'` | Icon's background color. | 2.36.0 | | icon-size | `number` | `40` | Icon's size. | 2.36.0 | | icon-src | `string` | `undefined` | Icon's URL. | 2.36.0 | | padding | `number \| string` | `12` | Padding size of the QR Code. | 2.36.0 | | value | `string` | `''` | Text information. | 2.36.0 | | size | `number` | `100` | Size of the qrcode. | 2.36.0 | | type | `'canvas'` \| `'svg'` | `'canvas'` | Customize Render Type. | 2.38.2 | ### About QR code error correction level The error correction level of the two-dimensional code refers to the error correction capability used in the generation of the two-dimensional code, which determines the ability of the two-dimensional code to be correctly decoded when it is damaged or partially invisible. Two-dimensional code standards (such as QR codes) define four error correction levels: L, M, Q, and H. Each level provides different error correction capabilities and tolerance. - `L (Low)`: Provides approximately `7%` recovery capability. - `M (Middle)`: Provides approximately `15%` recovery capacity. - `Q (High)`: Provides approximately `25%` recovery capacity. - `H (Max)`: Provides approximately `30%` recovery capacity. Selecting a higher error correction level can improve the fault tolerance of the two-dimensional code, that is, it can still be correctly decoded under a certain degree of damage or deformation, but at the same time, it will increase the density of the two-dimensional code, making the two-dimensional code occupy a larger space. --- # Statistic As simple as it looks. ## Demos ### Basic ```vue ``` ## API ### Statistic Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | label | `string` | `undefined` | Label of the statistics. | | | tabular-nums | `boolean` | `false` | Whether to make numbers with same width. | 2.23.2 | | value | `string \| number` | `undefined` | Statistics value. | | ### Statistic Slots | Name | Parameters | Description | | ------- | ---------- | ------------- | | default | `()` | Value slot. | | label | `()` | Label slot. | | prefix | `()` | Value prefix. | | suffix | `()` | Value suffix. | --- # Table If you only want to render some basic tables, use it. If you want to render structured data, see [Data Table](https://www.naiveui.com/en-US/components/data-table.md). ## Demos ### Basic ```vue ``` ### Bordered ```vue ``` ### Size ```vue ``` ### Single column ```vue ``` ### Single line ```vue ``` ### Stripe ```vue ``` ## Components You can use `n-table`, `n-thead`, `n-tbody`, `n-tr`, `n-th` and `n-td`. At most time you won't need the components after `n-table`. They can be used to reduce the granularity of dependency collecting. ## API ### Table Props | Name | Type | Default | Description | | --- | --- | --- | --- | | bottom-bordered | `boolean` | `true` | The bottom border of the table, this prop is invalid when `bordered` is `true`. | | bordered | `boolean` | `true` | Whether to show table border. | | single-column | `boolean` | `false` | Whether rows are not divided. If the prop is `true`, table cell has no `border-bottom`. | | single-line | `boolean` | `true` | Whether columns are not divided. If the prop is `true`, table cell has no `border-right`. | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | Table size. | | striped | `boolean` | `false` | Whether to show zebra stripes on rows. | --- # Thing When you want to describe a thing, use thing. If you find it doesn't fit you demand, write one by yourself. I wish there is a way to build all kinds of frequently used layout inside a component. It takes me some time to figure out that the component already exist, the brower itself. ## Demos ### Basic Thing provides many slots to custom. ```vue ``` ### Content indented Content can be indented after avatar. ```vue ``` ## API ### Thing Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | content-indented | `boolean` | `false` | Whether to enable content indentation. | | content | `string` | `undefined` | Content area. | | content-class | `string` | `undefined` | Content area class. | 2.36.0 | | content-style | `string \| Object` | `undefined` | Content area style. | 2.32.2 | | description | `string` | `undefined` | Description information. | | description-class | `string` | `undefined` | Description area class. | 2.36.0 | | description-style | `string \| Object` | `undefined` | Description area style. | 2.32.2 | | title-extra | `string` | `undefined` | Additional information for the title. | | title | `string` | `undefined` | Title information. | ### Thing Slots | Name | Parameters | Description | | ------------ | ---------- | -------------------- | | action | `()` | Action's slot. | | avatar | `()` | Avatar's slot. | | default | `()` | Content's slot. | | description | `()` | Description's slot. | | footer | `()` | Footer's slot. | | header-extra | `()` | Header extra's slot. | | header | `()` | Header's slot. | --- # Time Time provide some basic formation for time. ## Demos ### Basic ```vue ``` ### Type `date`, `datetime` or `relative`. ```vue ``` ### Format Format time. Specs see [date-fns format](https://date-fns.org/v2.6.0/docs/format). ```vue ``` ### Relative `n-time` uses `date-fns`'s [`formatDistanceStrict`](https://date-fns.org/v2.28.0/docs/formatDistanceStrict) to format relative time. If you don't need much customization, this is enough. ```vue ``` ### Unix timestamp Use Unix timestamp as time. ```vue ``` ### Time zone ```vue ``` ## API ### Time Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | format | `string` | `undefined` | Time format. For detail please see [format](https://date-fns.org/v2.23.0/docs/format). | | | time | `number \| Date` | `Date.now()` | Time. | | | time-zone | `string` | `undefined` | Time zone to be used to format the value. It follows [iana time zones](https://www.iana.org/time-zones). You can use `Intl.supportedValuesOf('timeZone')` to check supported values. | 2.30.0 | | to | `number \| Date` | `Date.now()` | Target time. | | | type | `'relative' \| 'date' \| 'datetime'` | `'datetime'` | Time type. | | | unix | `boolean` | `false` | `unix` timestamp. | | --- # Timeline The world is 2 dimensioned. One of them is time. The Other is event. ## Demos ### Basic ```vue ``` ### Size ```vue ``` ### Item placement Left. .thgiR ```vue ``` ### Horizontal ```vue ``` ### Customize icon ```vue ``` ## API ### Timeline Props | Name | Type | Default | Description | | -------------- | --------------------- | ----------- | ------------------ | | horizontal | `boolean` | `'false'` | Horizontal | | icon-size | `number` | `undefined` | Size of icon part. | | item-placement | `'left' \| 'right'` | `'left'` | Direction. | | size | `'medium' \| 'large'` | `'medium'` | Size. | ### TimelineItem Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | color | `string` | `undefined` | Item color. | | | content | `string` | `undefined` | Item content. | | | line-type | `'default' \| 'dashed'` | `'default'` | Line type. | 2.26.1 | | time | `string` | `undefined` | Item time. | | | title | `string` | `undefined` | Item title. | | | type | `'default' \| 'success' \| 'info' \| 'warning' \| 'error'` | `'default'` | Item type. | | ### Timeline Slots | Name | Parameters | Description | | ------- | ---------- | ----------------- | | default | `()` | Timeline Content. | ### TimelineItem Slots | Name | Parameters | Description | | ------- | ---------- | ---------------------------------------------- | | default | `()` | Timeline item content. | | icon | `()` | Timeline item customize timeline icon. | | footer | `()` | Content at the bottom of the timeline options. | | header | `()` | Content at the top of the timeline options. | --- # Tree To be honest, I'm not good at biology. I can figure out few kinds of trees. What's more, not only biology, I forget balanced tree everytime after I revise it shortly. ## Demos ### Basic Fortunately, the tree is now alive and it's not balanced. ```vue ``` ### Customize key and label field Various data would come from backend. ```vue ``` ### Select multiple nodes Set `multiple` to select multiple nodes. ```vue ``` ### Cascade checking Set `cascade` to use cascade check. ```vue ``` ### Search Tree accept `pattern` and `filter` to do searching. ```vue ``` ### Drag & drop Set `draggable` and write bunch of codes to make drag & drop work. ```vue ``` ### Large data Set `virtual-scroll` to use virtual scroll. Note that you should set the height of the tree. ```vue ``` ### Async loading Use `on-load` callback to load data. When loading async, all nodes with `isLeaf` set to `false` and `chilren`'s type is not `Array` will be reckon as unloaded nodes. ```vue ``` ### Disabled nodes ```vue ``` ### Prefix and suffix Add some actions. ```vue ``` ### Batch rendering As you can see, prefix, label, and suffix all have render functions. ```vue ``` ### Switcher icon Use `render-switcher-icon` prop to customize switcher icon. ```vue ``` ### File Tree Use `on-update:expanded-keys` to change the prefix icon style of the node in different states. ```vue ``` ### Node events Use `node-props` to bind HTML attributes to node. For example click or contextmenu event listener. ```vue ``` ### Show Line ```vue ``` ### Checkbox Placement ```vue ``` ### Custom node click behavior You can use `override-default-node-click-behavior` prop to override default node click behavior. For example, you can change non-leaf key's default behavior to `'toggleExpand'` to simulate a file selector. ```vue ``` ## API ### Tree Props | Name | Type | default | Description | Version | | --- | --- | --- | --- | --- | | accordion | `boolean` | `false` | Whether to use accrodion expand mode. | 2.31.0 | | allow-checking-not-loaded | `boolean` | `false` | Whether to allow cascade checking on not loaded nodes. If you want to use this, you should know the `check-keys` may be incomplete. Also, you should aware about the consistency bewteen naive's checking logic and your backend's checking logic, especially when there are disabled nodes. | 2.28.1 | | allow-drop | `(info: { dropPosition: DropPosition, node: TreeOption, phase: 'drag' \| 'drop' }) => boolean` | A function that prohibit dropping inside leaf node. | Whether to allow dropping. | | | animated | `boolean` | `true` | Whether to show expand animation. | 2.33.4 | | block-line | `boolean` | `false` | Nodes spread out the whole row. | | | block-node | `boolean` | `false` | The node name is spread out in the whole row. | | | cancelable | `boolean` | `true` | Whether node's select status can be cancelled. | | | cascade | `boolean` | `false` | Whether to cascade checkboxes. | | | check-strategy | `string` | `'all'` | The strategy of setting checked callback's keys argument. `all` means setting all checked node. `parent` means setting all checked parent node of whom all child node are checked. `child` means setting all child node. | | | checkable | `boolean` | `false` | Whether to display the selection box. | | | checkbox-placement | `'left' \| 'right'` | `'left'` | Checkbox's placement. | 2.28.3 | | children-field | `string` | `'children'` | The children field in `TreeOption`. | | | checked-keys | `Array` | `undefined` | Checked keys of the tree. | | | check-on-click | `boolean \| ((node: TreeOption) => boolean)` | `false` | Allow node clicking to trigger check when `checkable` is `true`. | 2.31.0 | | data | `Array` | `[]` | The node data of the tree. Reset `data` will cause clearing of some uncontrolled status. If you need to modify data, you'd better make tree work in a controlled manner. | | | default-checked-keys | `Array` | `[]` | Multiple options selected by default. | | | default-expand-all | `boolean` | `false` | Expand all options. | | | default-expanded-keys | `Array` | `[]` | Expanded items by default. | | | default-selected-keys | `Array` | `[]` | Nodes selected by default. | | | draggable | `boolean` | `false` | Whether it can be dragged. | | | expand-on-dragenter | `boolean` | `true` | Whether to expand nodes after dragenter. | | | expand-on-click | `boolean` | `false` | Whether to expand or collapse nodes after click. | 2.29.1 | | expanded-keys | `Array` | `undefined` | If set, expanded status will work in controlled manner. | | | ellipsis | `boolean` | `false` | Whether to ellipsis the text that exceeds the width. | 2.43.0 | | filter | `(pattern: string, node: TreeOption) => boolean` | A simple string based filter. | The function that filter tree nodes based on pattern. | | | get-children | `(option: any) => unknown` | `undefined` | Get children of the option. | 2.34.3 | | indent | `number` | `24` | Indent of per level of the tree. | 2.9.0 | | indeterminate-keys | `Array` | `undefined` | Indeterminate keys of the tree. | | | keyboard | `boolean` | `true` | Whether to support keyboard operation. | 2.32.2 | | key-field | `string` | `'key'` | The key field in `TreeOption`. | | | label-field | `string` | `'label'` | The label field in `TreeOption`. | | | disabled-field | `string` | `'disabled'` | The disabled field in `TreeOption`. | 2.32.2 | | node-props | `(info: { option: TreeOption }) => HTMLAttributes` | `undefined` | HTML attributes of node. | 2.25.0 | | multiple | `boolean` | `false` | Whether to allow multiple selection of nodes. | | | on-load | `(node: TreeOption) => Promise` | `undefined` | Callback function for asynchronously loading data. If not data is loaded, you should make promise resolve `false` or be rejected, nor the loading animation won't end. | Non void Promise 2.34.3 | | override-default-node-click-behavior | `(info: { option: TreeSelectOption }) => 'toggleExpand' \| 'toggleSelect' \| 'toggleCheck' \| 'default' \| 'none'` | `undefined` | Override default node click behavior. | 2.37.0 | | pattern | `string` | `''` | What to search by default. | | | render-label | `(info: { option: TreeOption, checked: boolean, selected: boolean }) => VNodeChild` | `undefined` | Render function of all the options' label. | | | render-prefix | `(info: { option: TreeOption, checked: boolean, selected: boolean }) => VNodeChild` | `undefined` | Render function of all the options' prefix. | | | render-suffix | `(info: { option: TreeOption, checked: boolean, selected: boolean }) => VNodeChild` | `undefined` | Render function of all the options' suffix. | | | render-switcher-icon | `(props: { option: TreeOption, expanded: boolean, selected: boolean }) => VNodeChild` | `undefined` | Render function of option switcher icon. | 2.24.0, `props` 2.34.0 | | scrollbar-props | `ScrollbarProps` | `undefined` | See [Scrollbar props](https://www.naiveui.com/en-US/components/scrollbar.md#Scrollbar-Props). | | | selectable | `boolean` | `true` | Whether the node can be selected. | | | selected-keys | `Array` | `undefined` | If set, selected status will work in controlled manner. | | | show-irrelevant-nodes | `boolean` | `true` | Whether to filter unmached nodes when tree is in filter mode. | 2.28.1 | | show-line | `boolean` | `false` | Whether to display the connection line. | 2.35.0 | | spin-props | `{ strokeWidth?: number, stroke?: string, scale?: number, radius?: number }` | `undefined` | Loading icon properties. | 2.44.0 | | virtual-scroll | `boolean` | `false` | Whether to enable virtual scroll. You need to set proper style height of the tree in advance. | | | watch-props | `Array<'defaultCheckedKeys' \| 'defaultSelectedKeys' \|'defaultExpandedKeys'>` | `undefined` | Default prop names that needed to be watched. Components will be updated after the prop is changed. Note: the `watch-props` itself is not reactive. | | | on-dragend | `(data: { node: TreeOption, event: DragEvent }) => void` | `undefined` | The callback function after the node completes the dragging action. | | | on-dragenter | `(data: { node: TreeOption, event: DragEvent }) => void` | `undefined` | Callback function in node drag and drop. | | | on-dragleave | `(data: { node: TreeOption, event: DragEvent }) => void` | `undefined` | Drag a node, the callback function after the node leaves other nodes. | | | on-dragstart | `(data: { node: TreeOption, event: DragEvent }) => void` | `undefined` | Callback function to start dragging a certain node. | | | on-drop | `(data: { node: TreeOption, dragNode: TreeOption, dropPosition: 'before' \| 'inside' \| 'after', event: DragEvent }) => void` | `undefined` | The callback function after the node completes the dragging action. | | | on-update:checked-keys | `(keys: Array, option: Array), meta: { node: TreeOption \| null, action: 'check' \| 'uncheck' }) => void` | `undefined` | Callback function when node checked options change. | `meta` 2.34.0 | | on-update:indeterminate-keys | `(keys: Array, option: Array) => void` | `undefined` | Callback function when node indeterminate options change. | | | on-update:expanded-keys | `(keys: Array, option: Array), meta: { node: TreeOption \| null, action: 'expand' \| 'collapse' \| 'filter' }) => void` | `undefined` | The callback function when the node expansion item changes. | `meta` 2.34.0 | | on-update:selected-keys | `(keys: Array, option: Array), meta: { node: TreeOption \| null, action: 'select' \| 'unselect' }) => void` | `undefined` | The callback function when the selected item of the node changes. | `meta` 2.34.0 | ### TreeOption Properties | Name | Type | Description | | --- | --- | --- | | key | `string \| number` | Key of the node, should be unique. You can use `key-field` to customize the field name. | | label | `string` | Label of the node. You can use `label-field` to customize the field name. | | checkboxDisabled? | `boolean` | Whether the checkbox is disabled. | | children? | `TreeOption[]` | Child nodes of the node. | | disabled? | `boolean` | Whether the node is disabled. | | isLeaf? | `boolean` | Whether the node is leaf. Required in async expanding mode. | | prefix? | `string \| (() => VNodeChild)` | Prefix of the node. | | suffix? | `string \| (() => VNodeChild)` | Suffix of the node. | ### Tree Slots | Name | Parameters | Description | Version | | ----- | ---------- | ------------------------------ | ------- | | empty | `()` | Empty state slot for the tree. | | ## Methods ### Tree Methods | Name | Paramaters | Description | Version | | --- | --- | --- | --- | | scrollTo | `ScrollTo` | Scroll to some node in virtual scroll mode. | 2.32.2, `ScrollTo` 2.37.0 | | getCheckedData | `() => { keys: Array, options: Array }` | Get checked data. | 2.34.1 | | getIndeterminateData | `() => { keys: Array, options: Array }` | Get indeterminate data. | 2.34.1 | #### ScrollTo Type ```ts interface ScrollTo { (x: number, y: number): void (options: { left?: number, top?: number, debounce?: boolean }): void (options: { index: number, debounce?: boolean }): void (options: { key: string | number, debounce?: boolean }): void (options: { position: 'top' | 'bottom', debounce?: boolean }): void } ``` ### Others 1. `treeGetClickTarget: (e: MouseEvent) => ('checkbox' | 'switcher' | 'node')`: Get click target of a node click event. It can be used in `nodeProps.onClick`. You can import it from `naive-ui` package directly. --- # Infinite Scroll Scroll, scroll, scroll, scroll... Available since `2.38.2`. ## Demos ### Basic ```vue ``` ### A bit complex example ```vue ``` ## API ### Infinite Scroll Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | distance | `number` | `0` | Distance threshold that triggers loading. | 2.38.2 | | scrollbar-props | `Object` | `undefined` | Attribute reference [Scrollbar props](https://www.naiveui.com/en-US/components/scrollbar.md#Scrollbar-Props). | 2.38.2 | | on-load | `() => Promise \| void` | `undefined` | The callback function when scrolling to the bottom. | 2.38.2 | --- # Highlight If you've used a search engine, you should know what it is. Available since `2.40.0`. ## Demos ### Basic ```vue ``` ### Style Change the style to make the highlight more striking. ```vue ``` ### Case sensitive By default, highlighting is case-sensitive, which you can turn on using the `case-sensitive` property. ```vue ``` ### Highlight Tag The `highlight-tag` property allows you to specify tag for highlighted text. ```vue ``` ## API ### Highlight Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | auto-escape | `boolean` | `true` | Whether to escape `patterns` automatically. By default, elements in `patterns` will be converted into regular expressions for matching, and this process includes automatic escaping, so that the regular expressions will match the literal content of the elements. For example, `\(` will match `\(`. If you need the n-highlight component to match using regular expressions constructed from the elements in `patterns` themselves (e.g., `\(` matches `(`), you can set this to false. If you do not understand these details, do not change this setting. | 2.40.0 | | case-sensitive | `boolean` | `false` | Case sensitive or not. | 2.40.0 | | highlight-class | `string` | `undefined` | Class name of the highlight content. | 2.40.0 | | highlight-style | `Object \| string` | `undefined` | Style of the highlight content. | 2.40.0 | | highlight-tag | `string` | `'mark'` | HTML element tag of the highlight content. | 2.40.0 | | patterns | `string[]` | `undefined` | Highlight text. | 2.40.0 | | text | `string` | `undefined` | Text. | 2.40.0 | --- # Heatmap Digital workers have their own wall to paint. Available from `2.43.0`. > **Usage Prerequisites** > > Color-related properties `active-colors` and `minimum-color` have higher priority than `color-theme`. If these three properties are set simultaneously, `active-colors` and `minimum-color` will be used. It is recommended not to set them at the same time. > When none are set, the default value built into Naive UI is used - a GitHub-style theme. ## Demos ### Basic Every square is a piece of persistence, and blanks are the rhythm of life. ```vue ``` ### Built-in Themes Use the `color-theme` prop to apply built-in color themes. Available themes: `green`, `blue`, `orange`, `purple`, `red`. ```vue ``` ### Custom Colors Each color has its own temperature. ```vue ``` ### Slots Customize footer area with `footer` slot and `indicator` slot. Also supports custom `tooltip` content and indicator text slots. ```vue ``` ## API ### Heatmap Props Type `HeatmapProps` | Name | Type | Related Type | Default | Description | Version | | --- | --- | --- | --- | --- | --- | | active-colors | `string[]` | - | `undefined` | Color array arranged from light to dark, higher priority than `color-theme`. | 2.43.0 | | color-theme | `'green' \| 'blue' \| 'orange' \| 'purple' \| 'red'` | `HeatmapColorTheme` | `undefined` | Built-in color theme. | 2.43.0 | | data | `Array<{ timestamp: number, value?: number \| null }>` | `HeatmapData`, `HeatmapDataItem` | `[]` | Heatmap data containing timestamp and value. | 2.43.0 | | first-day-of-week | `0 \| 1 \| 2 \| 3 \| 4 \| 5 \| 6` | `HeatmapFirstDayOfWeek` | `0` | Start day of the week, 0 for Monday, 6 for Sunday. | 2.43.0 | | fill-calendar-leading | `boolean` | - | `false` | Whether to fill the leading of calendar grid, suitable for GitHub style recent year view. | 2.43.0 | | loading | `boolean` | - | `false` | Whether to show loading state. | 2.43.0 | | loading-data | `Array<{ timestamp: number, value?: number \| null }>` | `HeatmapData`, `HeatmapDataItem` | `undefined` | Data to display in loading status. If item's `value` is `null`, cell is hidden but will occupy place. If. item's `value` is anything but `null`, cell will show loading status. | 2.43.0 | | minimum-color | `string` | - | `undefined` | Minimum color for the heatmap, defaults to the first color in `active-colors`. | 2.43.0 | | show-color-indicator | `boolean` | - | `true` | Whether to show the color level indicator at the bottom | 2.43.0 | | show-month-labels | `boolean` | - | `true` | Whether to show month labels. | 2.43.0 | | show-week-labels | `boolean` | - | `true` | Whether to show week labels. | 2.43.0 | | size | `'small' \| 'medium' \| 'large'` | - | `'medium'` | Heatmap size. | 2.43.0 | | tooltip | `boolean \| TooltipProps` | - | `false` | Tooltip configuration, `false` to disable, object for `TooltipProps`. | 2.43.0 | | x-gap | `number \| string` | - | `undefined` | Horizontal gap | 2.43.0 | | y-gap | `number \| string` | - | `undefined` | Vertical gap | 2.43.0 | ### Heatmap Slots Type `HeatmapSlots` | Name | Parameters | Related Type | Description | Version | | --- | --- | --- | --- | --- | | footer | `()` | - | Left footer slot, aligned with the left side of heatmap table | 2.43.0 | | indicator | `()` | - | Right footer indicator slot, aligned with the right side of heatmap table | 2.43.0 | | indicator-leading-text | `()` | - | Leading text for the color level indicator | 2.43.0 | | indicator-trailing-text | `()` | - | Trailing text for the color level indicator | 2.43.0 | | tooltip | `(props: { timestamp: number, value?: number \| null })` | `HeatmapTooltipSlotProps` | Custom tooltip content | 2.43.0 | ### Others 1. `import { heatmapMockData } from 'naive-ui'`, `function heatmapMockData(year?: 'recent' | number): HeatmapData` --- # Affix Affix can make content stick to fixed places when scrolling. It's similar to `position: sticky` but can do more things. ## Demos ### Basic Affix has `trigger-top`, `top`, `trigger-bottom` and `bottom`. `trigger-top` is top affixing trigger point. `top` is the style `top` value after top affixing is trigger. `trigger-bottom` and `bottom` work in similar way. ```vue ``` ### Position Affix can be `absolute` or `fixed` positioned. You may need some css tricks to make it works as following. By default position is set to `fixed`, because in most cases scrolled element is `document`. ```vue ``` ## API ### Affix Props | Name | Type | Default | Description | | --- | --- | --- | --- | | bottom | `number` | `undefined` | The css bottom property after trigger bottom affix. (if not set, use `trigger-bottom` prop) | | listen-to | `string \| HTMLElement \| Document \| Window \| (() => HTMLElement)` | `document` | The scrolling element to listen scrolling. | | trigger-bottom | `number` | `undefined` | The distance px to bottom of target to trigger bottom affix. (if not set, use `bottom` prop) | | trigger-top | `number` | `undefined` | The distance px to top of target to trigger top affix. (if not set, use `top` prop) | | position | `'fixed' \| 'absolute'` | `'fixed'` | CSS position of the affix. | | top | `number` | `undefined` | The css top property after trigger top affix. (if not set, use `trigger-top` prop) | --- # Anchor Tell you where you are. ## Demos ### Basic ```vue ``` ### Ignore gap ```vue ``` ### Affix When in affix mode, Anchor can recieve addition props as same as Affix. ```vue ``` ### Scroll to ```vue ``` ## API ### Anchor Props | Name | Type | Default | Description | | --- | --- | --- | --- | | affix | `boolean` | `false` | If it works like an affix. If set to `true`, it will receive props from [affix](https://www.naiveui.com/en-US/components/affix.md#Affix-Props). | | bound | `number` | `12` | The height of the border when scrolling. | | ignore-gap | `boolean` | `false` | If set to `true`, it will be displayed on the exact href. | | offset-target | `string \| HTMLElement \| Window \| Document \| (() => HTMLElement)` | `document` | The element or selector used to calc offset of link elements. If you are not scrolling the entire document but only a part of it, you may need to set this. | | show-rail | `boolean` | `true` | Whether to show the sider rail. | | show-background | `boolean` | `true` | Whether to show background of links. | | type | `'rail' \| 'block'` | `'rail'` | The type to use. | ### AnchorLink Props | Name | Type | Default | Description | | ----- | -------- | ----------- | ------------------- | | href | `string` | `undefined` | The target of link | | title | `string` | `undefined` | The content of link | ### AnchorLink Slots | Name | Parameters | Description | Version | | ----- | ---------- | ---------------------- | ------- | | title | `()` | The title of the link. | 2.42.0 | ### Anchor Methods | Name | Type | Description | | --- | --- | --- | | scrollTo | `(href: string) => void` | Manually scroll to the specific position. | --- # Back Top It helps you back to where you were. However, time never goes back. ## Demos Scroll down to see demos work. ### Basic BackTop will find its first scrollable ascendant element and listen scroll event on it. ```vue ``` ### Visibility height You can change visibility height of backtop. ```vue ``` ### Change position For example: right 40px & bottom 160px. ```vue ``` ### Target to be listened to You can specify target to listen scroll event of. ```vue ``` ## API ### BackTop Props | Name | Type | Default | Description | | --- | --- | --- | --- | | bottom | `number \| string` | `40` | The height of BackTop from the bottom of the page | | listen-to | `string \| HTMLElement` | `undefined` | The element to be listened to scroll event. If it is `undefined` back top will listen to the nearest scrollable parent. | | right | `number \| string` | `40` | The width of BackTop from the right side of the page | | show | `boolean` | `undefined` | Whether to show BackTop | | to | `string \| HTMLElement` | `'body'` | Container node to show BackTop | | visibility-height | `number` | `180` | BackTop's trigger scroll top. | | on-update:show | `(value: boolean) => void` | `undefined` | Callback is triggered when back-top display changes. | --- # Breadcrumb It doesn't look like what it calls. ## Demos ### Basic ```vue ``` ### Dropdown It is possible to pass a custom template when you want to customize the item link to be, for example a `dropdown` or a `router-link`. ```vue ``` ### Customize separator Use separator prop to custom separator. ```vue ``` ### Custom separator by item Use separator prop or separator slot to custom separator of an item. When both are present, separator slot will be used. ```vue ``` ## API ### Breadcrumb Props | Name | Type | Default | Description | | --------- | -------- | ------- | --------------------- | | separator | `string` | `'/'` | Breadcrumb separator. | ### BreadcrumbItem Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | clickable | `boolean` | `true` | Whether it's clickable. | 2.30.0 | | href | `string` | `undefined` | BreadcrumbItem link. | | | separator | `string` | `undefined` | BreadcrumbItem separator. | | | show-separator | `boolean` | `true` | Whether to show the separator. | 2.44.0 | ### Breadcrumb Slots | Name | Parameters | Description | | ------- | ---------- | ------------------------ | | default | `()` | Breadcrumb default slot. | ### Breadcrumb Item Slots | Name | Parameters | Description | | --------- | ---------- | ------------------------------ | | default | `()` | BreadcrumbItem default slot. | | separator | `()` | BreadcrumbItem separator slot. | --- # Loading Bar A kind of good placebo for anxiety. > **Prerequisite** > > If you want to use loading bar, you need to wrap the component where you call related methods inside `n-loading-bar-provider` and inject `loadingBar`. For example: ```html ``` ```js import { useLoadingBar } from 'naive-ui' import { defineComponent } from 'vue' // content export default defineComponent({ setup() { const loadingBar = useLoadingBar() return { loading() { loadingBar.start() } } } }) ``` ## Demos ### Basic ```vue ``` ### Use loading bar locally You can set mount target of loading by `to` prop. ```vue ``` ## API ### LoadingBarProvider Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | container-class | `string` | `undefined` | Class of the loading bar container. | 2.33.4 | | container-style | `string \| object` | `undefined` | Style of the loading bar container. | 2.33.4 | | loading-bar-style | `{ loading?: string \| object, error?: string \| object }` | `undefined` | Style of the loading bar. | | | to | `string \| HTMLElement \| false` | `undefined` | Mount target of loading bar. | 2.33.4 | ### loadingBar Injection Methods | Name | Type | Description | | --- | --- | --- | | error | `() => void` | Callback function for loading bar error. | | finish | `() => void` | The callback function when the loading bar finishes loading. | | start | `() => void` | Callback function for loading bar to start loading. | --- # Menu No Food. ## Demos ### Horizontal A horiziontal menu which can automatically collapse its items. ```vue ``` ### Select & routing Usually you can use vue-router here to accomplish routing. Also, you can render `label` as `` or `` to set route. ```vue ``` ### Batch customizing menu options The `render-label`, `render-icon`, `expand-icon` can be used to batch render menu options. ```vue ``` ### Expand submenu If you don't set `default-expanded-keys`, menu will expand all the ascendant of selected option by default. ```vue ``` ### Indent You can specify `indent` & `root-indent` of the menu. `root-indent` only determines the first-leveled children. ```vue ``` ### Collapsed menu Use collapsable vertical menu with layout sider. Use `collapsed` to control collapse status of menu. You must set `collapsed-width` to make it collapse in a right manner. There are still some other collapse related props you can modify: `icon-size`, `collapsed-icon-size`. For details see API table at the bottom of the page. ```vue ``` ### Inverted Set `inverted` to add contrast. Usually used with `n-layout`. ```vue ``` ### Long label Set `label` to render function that renders `n-ellipsis`. ```vue ``` ### Accordion Like an accordion. You can use `accordion` prop to switch this mode for the first-level menu. ```vue ``` ### Use vue-router Usually you can use vue-router here to accomplish routing. You can render `label` as `` to set route. ```vue ``` ### Customizing field Various data would come from backend, you can customize `key`, `label` and `children`'s field name. ```vue ``` ### Show selected option In some scenes, menu's value is passed from outside. The component is hard to understand what behavior is expected. You can use `showOption` method to make specified option displayed. ```vue ``` ### Control option visibility In some cases, different roles will see different options. You can use the `show` field to control the visibility of menu options. ```vue ``` ## API ### Menu Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | accordion | `boolean` | `false` | Whether to use accordion mode. | | | children-field | `string` | `'children'` | Field name of children. | | | collapsed-icon-size | `number` | `24` | The icon size when menu is collapsed. If not set, menu will use `icon-size` in place of it. | | | collapsed-width | `number` | `48` | The menu width after collapsed. | | | collapsed | `boolean` | `false` | The collapsed status of menu, only works when menu is vertical. | | | default-expand-all | `boolean` | `false` | Whether to expand all menus. When options is set asynchronously, you can set `watch-props` to `['defaultExpandedKeys']` to make it work. | | | default-expanded-keys | `Array` | `[]` | The default expanded submenu keys of menu in uncontrolled manner. | | | default-value | `string \| null` | `null` | Whether selected by default in uncontrolled mode. | | | disabled-field | `string` | `'disabled'` | Field name of disabled. | 2.33.0 | | dropdown-placement | `'top-start' \| 'top' \| 'top-end' \| 'right-start' \| 'right' \| 'right-end' \| 'bottom-start' \| 'bottom' \| 'bottom-end' \| 'left-start' \| 'left' \| 'left-end' \| ` | `'top'` | Only effective in horizontal mode. | | | dropdown-props | `DropdownProps` | `undefined` | The dropdown's props when menu is collapsed or horizontal mode,please see [Dropdown Props](https://www.naiveui.com/en-US/components/dropdown.md#Dropdown-Props) | | | expanded-keys | `Array` | `undefined` | The expanded submenu keys. If set, menu will work in controlled manner and `default-expanded-names` won't work. | | | expand-icon | `(option: MenuOption) => VNodeChild` | `undefined` | Render function that renders all expand icon. | | | icon-size | `number` | `20` | The icon size when menu is not collapsed. | | | indent | `number` | `32` | The indent of menu. | | | inverted | `boolean` | `false` | Use inverted style. | | | key-field | `string` | `'key'` | Field name of key. | | | label-field | `string` | `'label'` | Field name of label. | | | options | `Array` | `[]` | Items data of menu. | | | node-props | `(option: MenuOption \| MenuGroupOption) => object` | `undefined` | Node's DOM attrs generator. | 2.28.3 | | mode | `'vertical' \| 'horizontal'` | `'vertical'` | Menu layout. | | | render-extra | `(option: MenuOption \| MenuGroupOption) => VNodeChild` | `undefined` | Render function that renders all extras. | | | render-icon | `(option: MenuOption) => VNodeChild` | `undefined` | Render function that renders all icons. | | | render-label | `(option: MenuOption \| MenuGroupOption) => VNodeChild` | `undefined` | Render function that renders all labels. | | | responsive | `boolean` | `false` | Whether to collapsed menu items that overflows menu. Only work for menu with `mode='horizontal'`. | 2.36.0 | | root-indent | `number` | `undefined` | The indent of menu's first level children. If not set, menu will use `indent` in place of it. | | | value | `string \| null` | `undefined` | The selected item key of the menu. | | | watch-props | `Array<'defaultValue' \| 'defaultExpandedKeys'>` | `undefined` | Default prop names that needed to be watched. Components will be updated after the prop is changed. Note: the `watch-props` itself is not reactive. | | | on-update:expanded-keys | `(keys: string[]) => void` | `undefined` | `keys` is the array of expanded menu options' `key`. | | | on-update:value | `(key: string, item: MenuOption) => void` | `undefined` | Callback when select a menu item. `key` is the `key` of the selected menu item. `item` is then original data of the menu item. | | ### MenuOption Properties | Name | Type | Description | Version | | --- | --- | --- | --- | | children? | `Array` | Child menu options. | | | disabled? | `boolean` | Whether to disable the menu item. | | | extra? | `string \| (() => VNodeChild)` | The extra parts of the menu item. | | | icon? | `() => VNodeChild` | The icon for the menu item. | | | key | `string` | The identifier of the menu item. | | | label | `string \| (() => VNodeChild)` | The label of the menu item. | | | show? | `boolean` | Whether to show the menu item. | 2.32.2 | ### MenuGroupOption Properties | Name | Type | Description | Version | | --- | --- | --- | --- | | children | `Array` | Group items, **required!** | | | key | `string` | The identifier of the menu group. | | | label | `string \| (() => VNodeChild)` | The label of the menu item. | | | show? | `boolean` | Whether to show the menu item. | 2.32.2 | | type | `'group'` | The type of the menu item, **required!** | | ### MenuDividerOption Properties | Name | Type | Description | Version | | --- | --- | --- | --- | | key | `string` | The identifier of the menu group. | | | props | `HTMLAttributes` | Attributes of the divider. | | | show? | `boolean` | Whether to show the menu item. | 2.32.2 | | type | `'divider'` | The type of the menu item, **required!** | | ### Menu Methods | Name | Type | Description | Version | | --- | --- | --- | --- | | deriveResponsiveState | `() => void` | Recalculate the collapsed state of the responsive menu content. When the width of the menu container is not solely determined by the external width, in the `responsive` mode, the menu content cannot automatically expand after being collapsed. You can call this method to ensure that the menu can be expanded again. | 2.36.0 | | showOption | `(key: string \| number) => void` | Expand menu to show option with specified `key`. If `key` is not specified, selected option will be displayed. | 2.27.0 | --- # Pagination Long data's friend. ## Demos ### Basic ```vue ``` ### Simple mode ```vue ``` ### Page slot The pagination has a property `page-slot`, try it and you will understand. It aims to solving misclicks caused by the length changing of pagination. ```vue ``` ### Quick jumper You can customize the content to jump to (press `Enter` to jump quickly). ```vue ``` ### Size ```vue ``` ### Size picker ```vue ``` ### Disabled ```vue ``` ### Use item count Sometime you don't want set `page-count`. At that time you may use `item-count` and `page-size`. ```vue ``` ### Customize the previous and next button ```vue ``` ### Prefix & suffix You may want to add something before and after. ```vue ``` ### Custom page size options ```vue ``` ## API ### Pagination Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | default-page | `number` | `1` | Current page in uncontrolled mode. | | | default-page-size | `number` | `10` | Page size in uncontrolled mode. | | | disabled | `boolean` | `false` | Whether to disable the pagination. | | | display-order | `Array<'pages' \| 'size-picker' \| 'quick-jumper'>` | `['pages', 'size-picker', 'quick-jumper']` | Display order of different parts. | 2.32.2 | | goto | `() => VNodeChild` | `undefined` | Fast jump content render function. | 2.34.3 | | item-count | `number` | `undefined` | Total number. | | | next | `(info: PaginationInfo) => VNodeChild` | `undefined` | Next page. | | | prev | `(info: PaginationInfo) => VNodeChild` | `undefined` | Previous page. | | | label | `PaginationRenderLabel` | `undefined` | Item content. | 2.24.0 | | page-count | `number` | `1` | Total pages. | | | page-sizes | `Array` | `[10]` | Number of items per page, can be customize. | | | page-size | `number` | `undefined` | Page size in controlled mode. | | | page-slot | `number` | `9` | The number of pages displayed. | | | page | `number` | `undefined` | Current page in controlled mode. | | | prefix | `(info: PaginationInfo) => VNodeChild` | `undefined` | Paging prefix. | | | scrollbar-props | `ScrollbarProps` | `undefined` | See [Scrollbar props](https://www.naiveui.com/en-US/components/scrollbar.md#Scrollbar-Props) | 2.44.0 | | select-props | `SelectProps` | `undefined` | Page size select's props. | 2.34.3 | | show-quick-jumper | `boolean` | `false` | Whether to show quick jump input. | | | show-quick-jump-dropdown | `boolean` | `true` | Whether to show quick jump dropdown. If you have too many pages, it could cause performance issue to create quick jump dropdown data. You can set it to `false` to enhance render performance. | 2.37.0 | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | size of page item. | 2.29.0 | | simple | `boolean` | `false` | Whether to use simple mode. | 2.32.2 | | suffix | `(info: PaginationInfo) => VNodeChild` | `undefined` | Page suffix. | | | show-size-picker | `boolean` | `false` | Whether to show the selector of the number of items per page. | | | to | `string \| HTMLElement \| false` | `body` | Container node of the pop menu. `false` will keep it not detached. | 2.33.4 | | on-update:page | `(page: number) => void` | `undefined` | Callback function when the current page changes. | | | on-update:page-size | `(pageSize: number) => void` | `undefined` | Callback function when the current page size changes. | | #### PaginationRenderLabel Type ```ts type PaginationRenderLabel = ( info: | { type: 'fast-backward' | 'fast-forward' node: VNode active: boolean } | { type: 'page' node: number active: boolean } ) => VNodeChild ``` #### PaginationInfo Type ```ts interface PaginationInfo { startIndex: number endIndex: number page: number pageSize: number pageCount: number itemCount: number | undefined } ``` ### Pagination Slots | Name | Parameters | Description | Version | | --- | --- | --- | --- | | goto | `()` | Fast jump text before quick jumper. | 2.27.0 | | label | The same as `PaginationRenderLabel`'s parameters | Item content. | 2.24.0 | | next | `(info: PaginationInfo)` | Next page. | | | prev | `(info: PaginationInfo)` | Previous page. | | | prefix | `(info: PaginationInfo)` | Page prefix. | | | suffix | `(info: PaginationInfo)` | Page suffix. | | --- # Steps 1, 2, 3... done! ## Demos ### Basic ```vue ``` ### Size Steps has `small`, `medium` size. ```vue ``` ### Vertical ```vue ``` ### Content Placement ```vue ``` ### Use slot in step ```vue ``` ### Customizing icon `'finish'` and `'error'` states icon or index icon can be customized. ```vue ``` ### Click to switch If `@update:current` is set, you can switch step by click. ```vue ``` ## API ### Steps Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | content-placement | `'right' \| 'bottom'` | `right` | Steps content placement, only can be used in horizontal mode. | 2.43.2 | | current | `number` | `undefined` | Currently active step index. | | | size | `'small' \| 'medium'` | `'medium'` | Steps size. | | | status | `'process' \| 'finish' \| 'error' \| 'wait'` | `'process'` | Steps status. | | | vertical | `boolean` | `false` | Steps vertical. | | | on-update:current | `(index: number) => void` | `undefined` | Callback on currently active step index changed. If it's set, step can be switched by click. | 2.29.1 | ### Step Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | description | `string` | `undefined` | Step description. | | | disabled | `boolean` | `false` | Whether it's clickable. | 2.29.1 | | status | `'process' \| 'finish' \| 'error' \| 'wait'` | `undefined` | Step status. | | | title | `string` | `undefined` | Step title. | | ### Steps Slots | Name | Parameters | Description | | ----------- | ---------- | -------------------------------- | | default | `()` | Steps content. | | finish-icon | `()` | `'finish'` status button deploy. | | error-icon | `()` | `'error'` status button deploy. | ### Step Slots | Name | Parameters | Description | Version | | ------- | ---------- | ------------- | ------- | | default | `()` | Step content. | | | icon | `()` | Step icon. | 2.26.1 | | title | `()` | Step title. | | --- # Tabs Switch contents in same area. > **Note** > > `n-tabs` will extract default tab value from default slot, so there would be a vue slot warning. If you don't want to see the warning, you should give component a `default-value`. ## Demos ### Basic ```vue ``` ### Segment Tabs of segment type. ```vue ``` ### Card type Set `type='card'`. ```vue ``` ### Flex tabs Only works with `'line'` or `'bar'` typed tabs. ```vue ``` ### Prefix & suffix Use `prefix` & `suffix` slot to add prefix & suffix. ```vue ``` ### Size Tabs may have different sizes. ```vue ``` ### Display directive You can set tab-panel's display directive to `if` or `show`. When use `show`, the tab-panel's content won't be reset after tab changes. When use `show:lazy`, the display effect is the same as `show`, but the content will be lazily loaded. ```vue ``` ### Addable Add some tabs. Only work with `'card'` type. ```vue ``` ### Hook before tab switching You can prevent or postpone tab switching. ```vue ``` ### No pane `n-tabs` always display a pane. If you only want to show tab, use `n-tab` instead of `n-tab-pane`. ```vue ``` ### Update bar manually Since `n-tabs` renders children directly, it can't understand your intention to update active tab. In some edge cases, you need to update bar position manually. ```vue ``` ### Set the width of the bar Do whatever you want. ```vue ``` ### Trigger You can use `trigger='hover'` to trigger activated tab. ```vue ``` ### Tabs placement ```vue ``` ### Scroll Buttons The scroll buttons are used to assist users in scrolling and switching when there are too many tabs. ```vue ``` ### Tab Scroll Centering When set to true, the active tab will scroll to the center of the scroll container. ```vue ``` ## API ### Tabs Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | addable | `boolean \| { disabled?: boolean }` | `false` | Whether to allow adding a tag. Only works when the tag's `type` is `card`. | | | add-tab-class | `string` | `undefined` | Class of the add tab. | 2.37.0 | | add-tab-style | `string \| object` | `undefined` | Style of the add tab. | 2.37.0 | | animated | `boolean` | `false` | Whether to activate tab switching animation. It has no effect if `placement` is `'left'`, `'right'`, `'start'` or `'end'`. | 2.27.0 | | bar-width | `number` | `undefined` | The width of the tab bar. | 2.25.0 | | center-active-tab | `boolean` | `false` | When set to true, the active tab will scroll to the center of the scroll container. | 2.45.0 | | closable | `boolean` | `false` | Whether to allow the tag to be closed. Only works when the tag's `type` is `card`. | | | default-value | `string \| number` | `undefined` | Default value in uncontrolled mode. | | | justify-content | `'space-between' \| 'space-around' \| 'space-evenly' \| 'start' \| 'center' \| 'end'` | `undefined` | Justify-content value of `flex` layout. Only works with `'line'` or `'bar'` typed tabs. | `space-*` 2.29.1 | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | Size of tabs. | | | pane-class | `string` | `undefined` | Class of the pane. | | | pane-style | `string \| object` | `undefined` | Style of the pane. | | | pane-wrapper-class | `string` | `undefined` | Class of the pane wrapper. | 2.34.4 | | pane-wrapper-style | `string \| object` | `undefined` | Style of the pane wrapper. | 2.34.4 | | placement | `'left' \| 'right' \| 'top' \| 'bottom' \| 'start' \| 'end'` | `'top'` | Placement of tabs. `'start'` / `'end'` map to `'left'` / `'right'` according to RTL. It won't work with `n-tabs` whose `type` is `'segment'`. | 2.34.4, `start` `end` 2.45.0 | | show-scroll-button | `boolean` | `false` | Whether to display the scroll button. | 2.45.0 | | tab-class | `string` | `undefined` | Class of the tab. | 2.37.0 | | tab-style | `string \| object` | `undefined` | Style of the tab. | | | tabs-padding | `number` | `0` | Start & end `padding` of the group of tabs. | | | trigger | `'click' \| 'hover'` | `'click'` | Trigger of activating a tab | 2.27.0 | | type | `'bar' \| 'line' \| 'card' \| 'segment'` | `'bar'` | Tabs type. | | | value | `string \| number` | `undefined` | Value in controlled mode. | | | on-add | `() => void` | `undefined` | Callback function triggered when adding tag. | | | on-before-leave | `(activeName: string \| number, oldActiveName: string \| number \| null) => boolean \| Promise` | `undefined` | Hook function executed before switching tabs. Returning `false` or promise resolving `false` or promise rejection will prevent tab switching. | | | on-close | `(name: string \| number) => void` | `undefined` | Callback function triggered when closing a tag. | | | on-update:value | `(value: string \| number) => void` | `undefined` | Callback function triggered when the value changes. | | ### TabPane Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | closable | `boolean` | `false` | Whether to allow the tag to be closed. Only works when the tag's `type` is `card`. | | | disabled | `boolean` | `false` | Whether to disable the tab. | | | display-directive | `'if' \| 'show' \| 'show:lazy'` | `'if'` | The directive to use in conditionally rendering. `if` will use `v-if` and `show` will use `v-show`. When using the `show` directive, the status of tab won't be reset after tab changes. When use `show:lazy`, the display effect is the same as `show`, but the content will be lazily loaded. | | | name | `string \| number` | `undefined` | Required, the name of the tab. | | | tab | `string \| VNode \| () => VNodeChild` | `undefined` | Tab label. | | | tab-props | `Object` | `undefined` | DOM attributes of tab label. | 2.24.2 | ### Tab Props | Name | Type | Default | Description | | --- | --- | --- | --- | | closable | `boolean` | `false` | Whether to allow the tag to be closed. Only works when the tag's `type` is `card`. | | disabled | `boolean` | `false` | Whether to disable. | | name | `string \| number` | `undefined` | Required, the name of the tab. | ### Tabs Slots | Name | Parameters | Description | | ------- | ---------- | ------------- | | default | `()` | Tabs content. | | prefix | `()` | Tabs prefix. | | suffix | `()` | Tabs suffix. | ### TabPane Slots | Name | Parameters | Description | | ------- | ---------- | ------------------ | | default | `()` | Tab pane content. | | tab | `()` | Tab label content. | ### Tab Slots | Name | Parameters | Description | | ------- | ---------- | ------------ | | default | `()` | Tab content. | ### Tabs Methods | Name | Type | Description | Version | | ------------------ | ------------ | ------------------------ | ------- | | scrollToCurrentTab | `() => void` | Scroll to current tab. | 2.45.0 | | syncBarPosition | `() => void` | Sync tab bar's position. | 2.24.0 | --- # Alert According to my experience, the most frequent usage of it may be requesting for disabling AdBlocks. ## Demos ### Basic ```vue ``` ### Bordered ```vue ``` ### Closable ```vue ``` ### Icon ```vue ``` ### No icon ```vue ``` ### Marquee You can use `n-marquee` to achieve marquee effect. ```vue ``` ## API ### Alert Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | bordered | `boolean` | `true` | Whether the alert can show border. | 2.32.2 | | closable | `boolean` | `false` | Whether the alert can be closed. | | | show-icon | `boolean` | `true` | Whether to show the icon of alert. | | | title | `string` | `undefined` | Title of the alert. | | | type | `'default' \| 'info' \| 'success' \| 'warning' \| 'error'` | `'default'` | Alert type. | | | on-after-leave | `Function` | `undefined` | Callback function executed when the alert disappears. | | | on-close | `() => boolean \| Promise \| any` | `() => true` | The callback function executed when the close icon is clicked. | | ### Alert Slots | Name | Parameters | Description | | ------- | ---------- | --------------------------------------- | | default | `()` | The content of the alert. | | header | `()` | The content placed in the alert header. | | icon | `()` | Icon displayed in the alert. | --- # Badge I bet you have seen it and know how it should be applied. ## Demos ### Basic ```vue ``` ### Type Badge has `default`, `error`, `info`, `success`, `warning` types. ```vue ``` ### Processing Set `processing` prop to indicate it is processing. ```vue ``` ### Show zero Set `show-zero` prop to display zero. ```vue ``` ### Overflow Set `max` prop to handle overflow situation. ```vue ``` ### Controlled visibility ```vue ``` ### Customizing content Insert some custom content in it. ```vue ``` ### Customizing color ```vue ``` ### Raw ```vue ``` ### Offset ```vue ``` ## API ### Badge Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | color | `string` | `undefined` | Badge color. | | | dot | `boolean` | `false` | Show badge as dot. | | | max | `number` | `undefined` | The maximum number of the badge when its value overflows. | | | offset | `[string \| number, string \| number]` | `undefined` | Offset of the badge from the left and top of the default position. | 2.34.3 | | processing | `boolean` | `false` | Show processing status. | | | show-zero | `boolean` | `false` | Whether to display the badge, even if provided value equals 0. | | | show | `boolean` | `true` | Whether the badge should be shown altogether. | | | type | `'default' \| 'success' \| 'error' \| 'warning' \| 'info'` | `'default'` | Type of the badge. | | | value | `string \| number` | `undefined` | Badge's value. | | ### Badge Slots | Name | Parameters | Description | | ------- | ---------- | ---------------- | | default | `()` | Badge's content. | --- # Dialog Before taking action, please confirm. > **Prerequisite** > > If you want to use dialog, you need to wrap the component where you call related methods inside `n-dialog-provider` and use `useDialog` to get the API. For example: ```html ``` ```js import { useDialog } from 'naive-ui' import { defineComponent } from 'vue' // content export default defineComponent({ setup() { const dialog = useDialog() return { warning() { dialog.warning(options) } } } }) ``` ## Demos ### Basic Inject `dialog` to create a dialog. ```vue ``` ### Async Dialog can be async. ```vue ``` ### Use as a component Sometimes you may want to use a component. ```vue ``` ### Click on mask I think user is smart enough that they know if nothing happens after mask is clicked, they should click at confirm or cancel button. ```vue ``` ### Customize action Sometimes you may want to customize `action` and `content` . ```vue ``` ### Access all dialog instances You can use `useDialogReactiveList` to access all dialog reactive inside `n-dialog-provider`. ```vue ``` ## API ### useDialog API | Name | Type | Description | | --- | --- | --- | | destroyAll | `() => void` | Destroy all popup dialogs. | | create | `(options: DialogOptions) => DialogReactive` | Create a dialog. | | error | `(options: DialogOptions) => DialogReactive` | Use `error` type dialog. | | info | `(options: DialogOptions) => DialogReactive` | Use `info` type dialog. | | success | `(options: DialogOptions) => DialogReactive` | Use `success` type dialog. | | warning | `(options: DialogOptions) => DialogReactive` | Use `warning` type dialog. | ### useDialogReactiveList API `() => Ref` ### DialogOptions Properties | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | action | `() => VNodeChild` | `undefined` | Content of the operation area, must be a render function. | | | actionClass | `string` | `undefined` | The class name of the action area. | 2.38.2 | | actionStyle | `Object \| string` | `undefined` | The style of the action area. | 2.38.2 | | autoFocus | `boolean` | `true` | Whether to focus the first focusable element inside modal. | 2.28.3 | | blockScroll | `boolean` | `true` | Whether to disabled body scrolling when it's active. | 2.28.3 | | bordered | `boolean` | `false` | Whether to show `border`. | | | class | `any` | `undefined` | Class name of the dialog. | 2.33.0 | | closable | `boolean` | `true` | Whether to show `close` icon. | | | closeFocusable | `boolean` | `false` | Whether the close button is focusable. | 2.43.0 | | closeOnEsc | `boolean` | `true` | Whether to close the dialog when the Esc key is pressed | 2.26.4 | | content | `string \| (() => VNodeChild)` | `undefined` | Content, can be a render function. | | | contentClass | `string` | `undefined` | The class name of the content. | 2.38.2 | | contentStyle | `Object \| string` | `undefined` | The style of the content. | 2.38.2 | | draggable | `boolean \| { bounds?: 'none' }` | `false` | Whether it is draggable. | 2.41.0 | | iconPlacement | `'left' \| 'top'` | `'left'` | Icon placement. | | | icon | `() => VNodeChild` | `undefined` | `Render` function of `icon`. | | | loading | `boolean` | `false` | Whether to display `loading` status. | | | maskClosable | `boolean` | `true` | Whether the dialog can be closed by clicking the `mask`. | | | negativeButtonProps | `ButtonProps` | `undefined` | Cancel button's DOM props | 2.27.0 | | negativeText | `string` | `undefined` | Cancel button text. Corresponding button won't show if not set. | | | positiveButtonProps | `ButtonProps` | `undefined` | Confirm button's DOM props | 2.27.0 | | positiveText | `string` | `undefined` | Confirm button text. Corresponding button won't show if not set. | | | showIcon | `boolean` | `true` | Whether to show `icon`. | | | style | `string \| Object` | `undefined` | Style of the dialog. | | | title | `string \| (() => VNodeChild)` | `undefined` | Title, can be a render function. | | | titleClass | `string` | `undefined` | The class name of the content. | 2.38.2 | | titleStyle | `Object \| string` | `undefined` | The style of the content. | 2.38.2 | | transformOrigin | `'mouse' \| 'center'` | `'mouse'` | The transform origin of the dialog's display animation. | 2.34.0 | | type | `'error \| 'success' \| 'warning'` | `'warning'` | Dialog type. | | | zIndex | `number` | `undefined` | Z index of the dialog. | 2.43.0 | | onAfterEnter | `() => void` | `undefined` | Callback on enter animation ends. | 2.33.0 | | onAfterLeave | `() => void` | `undefined` | Callback on leave animation ends. | 2.33.3 | | onClose | `() => boolean \| Promise \| any` | `undefined` | The default behavior is closing the confirm. Return `false` or resolve `false` or `Promise rejected` will prevent the default behavior. | | | onNegativeClick | `(e: MouseEvent) => boolean \| Promise \| any` | `undefined` | The default behavior is closing the confirm. Return `false` or resolve `false` or `Promise rejected` will prevent the default behavior. | | | onPositiveClick | `(e: MouseEvent) => boolean \| Promise \| any` | `undefined` | The default behavior is closing the confirm. Return `false` or resolve `false` or `Promise rejected` will prevent the default behavior. | | | onMaskClick | `() => void` | `undefined` | Callback triggered when click the mask. | | ### DialogReactive API #### DialogReactive Properties All the properties can be modified dynamically. | Name | Type | Description | Version | | --- | --- | --- | --- | | actionClass | `string` | The class name of the action area. | 2.38.2 | | actionStyle | `Object \| string` | The style of the action area. | 2.38.2 | | bordered | `boolean` | Whether to show `border`. | | | class | `any` | Class name of the dialog. | 2.33.0 | | closable | `boolean` | Whether to show `close` icon. | | | closeFocusable | `boolean` | Whether the close button is focusable. | 2.43.0 | | closeOnEsc | `boolean` | Whether to close dialog on Esc is pressed. | 2.26.4 | | content | `string \| (() => VNodeChild)` | Content, can be a render function. | | | contentClass | `string` | The class name of the content. | 2.38.2 | | contentStyle | `Object \| string` | The style of the content. | 2.38.2 | | iconPlacement | `'left' \| 'top'` | Icon placement. | | | icon | `() => VNodeChild` | `Render` function of `icon`. | | | loading | `boolean` | Whether to display `loading` status. | | | maskClosable | `boolean` | Whether the dialog can be closed by clicking the `mask`. | | | negativeButtonProps | `ButtonProps` | Cancel button's DOM props | 2.27.0 | | negativeText | `string` | Corresponding button won't show if not set. | | | positiveButtonProps | `ButtonProps` | Confirm button's DOM props | 2.27.0 | | positiveText | `string` | Corresponding button won't show if not set. | | | show-icon | `boolean` | Whether to show `icon`. | | | style | `string \| Object` | Style of the dialog. | | | title | `string \| (() => VNodeChild)` | Can be a render function. | | | titleClass | `string` | The class name of the content. | 2.38.2 | | titleStyle | `Object \| string` | The style of the content. | 2.38.2 | | transformOrigin | `'mouse' \| 'center'` | The transform origin of the dialog's display animation. | 2.34.0 | | type | `'error \| 'success' \| 'warning'` | Dialog type. | | | onAfterEnter | `() => void \| undefined` | Callback on enter animation ends. | 2.33.0 | | onAfterLeave | `() => void \| undefined` | Callback on leave animation ends. | 2.33.3 | | onClose | `() => boolean \| Promise \| any` | The default behavior is closing the confirm. Return `false` or `resolve false` or `Promise rejected` will prevent the default behavior. | | | onEsc | `() => void` | Callback fired when the escape key is pressed and focus is within dialog. | 2.32.0 | | onNegativeClick | `(e: MouseEvent) => boolean \| Promise \| any` | The default behavior is closing the confirm. Return `false` or `resolve false` or `Promise rejected` will prevent the default behavior. | | | onPositiveClick | `(e: MouseEvent) => boolean \| Promise \| any` | The default behavior is closing the confirm. Return `false` or `resolve false` or `Promise rejected` will prevent the default behavior. | | #### DialogReactive Methods | Name | Type | Description | | ------- | ---- | --------------- | | destroy | `()` | Close `dialog`. | ### Dialog Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | action-class | `string` | `undefined` | The class name of the action area. | 2.38.2 | | action-style | `Object \| string` | `undefined` | The style of the action area. | 2.38.2 | | bordered | `boolean` | `false` | Whether to show `border`. | | | closable | `boolean` | `true` | Whether to show `close` icon. | | | close-focusable | `boolean` | `false` | Whether the close button is focusable. | 2.43.0 | | content | `string \| (() => VNodeChild)` | `undefined` | Can be a render function. | | | content-class | `string` | `undefined` | The class name of the content. | 2.38.2 | | content-style | `Object \| string` | `undefined` | The style of the content. | 2.38.2 | | icon-placement | `'left' \| 'top'` | `'left'` | Icon placement. | | | icon | `() => VNodeChild` | `undefined` | `Render` function of icon. | | | loading | `boolean` | `false` | Whether to display `loading` status. | | | negative-button-props | `ButtonProps` | `undefined` | Cancel button's DOM props | 2.27.0 | | negative-text | `string` | `undefined` | Corresponding button won't show if not set. | | | positive-button-props | `ButtonProps` | `undefined` | Confirm button's DOM props | 2.27.0 | | positive-text | `string` | `undefined` | Corresponding button won't show if not set. | | | show-icon | `boolean` | `true` | Whether to display the `icon`. | | | title | `string \| (() => VNodeChild)` | `undefined` | Title, can be a render function. | | | title-class | `string` | `undefined` | The class name of the content. | 2.38.2 | | title-style | `Object \| string` | `undefined` | The style of the content. | 2.38.2 | | type | `'error \| 'success' \| 'warning' \| 'info'` | `'warning'` | Dialog type. | | | on-close | `() => void` | `undefined` | Calback on close button clicked. | | | on-negative-click | `(e: MouseEvent) => void` | `undefined` | Callback on positive button clicked. | | | on-positive-click | `(e: MouseEvent) => void` | `undefined` | Callback on negative button clicked. | | ### Dialog Slots | Name | Parameters | Description | Version | | ------- | ---------- | ----------------- | ------- | | action | `()` | `Action` content. | | | default | `()` | Dialog content. | | | header | `()` | `Header` content. | | | icon | `()` | `Icon` content. | | | close | `()` | `Close` content. | 2.36.0 | --- # Drawer I think it is similar with modal, with a bit difference on placement. > **Caveat** > > If you need to use `n-drawer-content`, you should keep `n-drawer`'s `native-scrollbar` prop as `true`. ## Demos ### Basic ```vue ``` ### Multiple drawers ```vue ``` ### Closable Set `closable` on `n-drawer-content`. ```vue ``` ### Customize display area You can customize display area by `to` prop. Remember to set `:trap-focus="false"` and `:block-scroll="false"`, otherwise content outside drawer won't be focusable and body won't be scrollable. ```vue ``` ### Custom header and bottom content ```vue ``` ### Scroll content A demo with long scroll content. ```vue ``` ### Resizable drawer Remeber to use `default-width` or `default-height` with `resizable`. ```vue ``` ## API ### Drawer Props | Name | Parameters | Default | Description | Version | | --- | --- | --- | --- | --- | | auto-focus | `boolean` | `true` | Whether to focus the first focusable element inside drawer. | 2.24.2 | | block-scroll | `boolean` | `true` | Whether to disabled body scrolling when it's active. | 2.28.3 | | close-on-esc | `boolean` | `true` | Whether to close drawer on Esc is pressed. | 2.24.2 | | content-class | `string` | `undefined` | Class of drawer's scrollable content node. | 2.37.0 | | content-style | `string \| Object` | `undefined` | Style of drawer's scrollable content node. | | | default-width | `number \| string` | `251` | Default width of the drawer, works when placement is `left` and `right`. | 2.31.0 | | default-height | `number \| string` | `251` | Default height of the drawer, works when placement is `top` and `bottom`. | 2.31.0 | | display-directive | `'if' \| 'show'` | `'if'` | The display directive to use when `n-drawer` is rendered. `'if'` corresponds to `v-if` and `'show'` corresponds to `v-show`. | | | height | `number \| string` | `undefined` | Works when placement is `top` and `bottom`. | | | native-scrollbar | `boolean` | `true` | Whether to use native scrollbar on drawer. | | | mask-closable | `boolean` | `true` | Whether to emit `hide` event when click mask. | | | max-width | `number` | `undefined` | Max width of draggable drawer. | 2.35.0 | | max-height | `number` | `undefined` | Max height of draggable drawer. | 2.35.0 | | min-width | `number` | `undefined` | Min width of draggable drawer. | 2.35.0 | | min-height | `number` | `undefined` | Max height of draggable drawer. | 2.35.0 | | placement | `'top' \| 'right' \| 'bottom' \| 'left'` | `'right'` | Drawer placement. | | | resizable | `boolean` | `false` | Whether to resize the width / height of drawer. | 2.31.0 | | scrollbar-props | `ScrollbarProps` | `undefined` | See [Scrollbar props](https://www.naiveui.com/en-US/components/scrollbar.md#Scrollbar-Props). | | | show | `boolean` | `false` | Whether to show drawer. | | | show-mask | `boolean` | `true` | Whether to show mask. If set to `'transparent'`, transparent mask would be shown. If set to false, `trap-focus` will be disabled. | 2.28.3 | | to | `string \| HTMLElement` | `'body'` | Container node of the drawer. | | | trap-focus | `boolean` | `true` | Whether to trap focus inside drawer. | 2.24.2 | | width | `number \| string` | `undefined` | Works when placement is `left` and `right`. | | | z-index | `number` | `undefined` | Z index of the drawer. | 2.24.0 | | on-after-enter | `() => void` | `undefined` | Callback after drawer is opened. | 2.28.0 | | on-after-leave | `() => void` | `undefined` | Callback after drawer is closed. | 2.28.0 | | on-esc | `() => void` | `undefined` | Callback fired when the escape key is pressed and focus is within drawer. | 2.24.2 | | on-mask-click | `(e: MouseEvent) => void` | `undefined` | Callback triggered on mask clicked. | | | on-update:height | `(height: number) => void` | `undefined` | Callback trigger on drawer height change. | 2.31.0 | | on-update:show | `(show: boolean) => void` | `undefined` | Callback triggered on drawer display status would change. | | | on-update:width | `(width: number) => void` | `undefined` | Callback trigger on drawer width change. | 2.31.0 | ### DrawerContent Props | Name | Parameters | Default | Description | Version | | --- | --- | --- | --- | --- | | body-class | `string` | `undefined` | Drawer content's body class. | 2.37.0 | | body-style | `string \| Object` | `undefined` | Drawer content's body style. | | | body-content-class | `string` | `undefined` | Class of body's scrollable content node. | | | body-content-style | `string \| Object` | `undefined` | Style of body's scrollable content node. | 2.37.0 | | closable | `boolean` | `false` | Whether the drawer content is closable. | | | footer-class | `string` | `undefined` | Drawer content's footer class. | 2.37.0 | | footer-style | `string \| Object` | `undefined` | Drawer content's footer style. | | | header-class | `string` | `undefined` | Drawer content's header class. | 2.37.0 | | header-style | `string \| Object` | `undefined` | Drawer content's header style. | | | native-scrollbar | `boolean` | `true` | Whether to use native scrollbar on body part. | | | title | `string` | `undefined` | Drawer content title. | | | scrollbar-props | `ScrollbarProps` | `undefined` | See [Scrollbar props](https://www.naiveui.com/en-US/components/scrollbar.md#Scrollbar-Props). | | ### Drawer Slots | Name | Parameters | Description | | ------- | ---------- | -------------------------- | | default | `()` | The content of the drawer. | ### DrawerContent Slots | Name | Parameters | Description | | ------- | ---------- | ---------------------------------- | | default | `()` | The content of the drawer content. | | footer | `()` | The footer of the drawer content. | | header | `()` | The header of the drawer content. | --- # Marquee A trivia: There's a deprecated HTML Element called `marquee`. Available since `2.40.2`. ## Demos ### Basic Put text into marquee: ```vue ``` ### Image You can put any content inside marquee. ```vue ``` ### Auto fill Use `auto-fill` prop to fill all the blank space that left. ```vue ``` ## API ### Marquee Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | auto-fill | `boolean` | `false` | Whether to fill the blank of the container using its content repeatly. | 2.40.2 | | speed | `number` | `48` | The speed calculated as pixels/second. | 2.40.2 | ### Marquee Slots | Name | Parameters | Description | Version | | ------- | ---------- | ----------- | ------- | | default | `()` | Content. | 2.40.2 | --- # Message Oracle from the top(always) of the browser. > **Notice** > > - If you want to use `useMessage` to use message, you need to put the component that calls its method inside `n-message-provider` and use `useMessage` to get the API. > - If you want to know how to use it outside of `setup`, please refer to Q & A at the bottom of this page. For example: ```html ``` ```js import { useMessage } from 'naive-ui' import { defineComponent } from 'vue' // content export default defineComponent({ setup() { const message = useMessage() return { warning() { message.warning('...') } } } }) ``` ## Demos ### Basic ```vue ``` ### Icon ```vue ``` ### Timing Specify the duration of messages. ```vue ``` ### Closable Set `closable` to make message closable by a click. ```vue ``` ### Modify exist message ```vue ``` ### Manually close ```vue ``` ### Caveat about theme If you don't specify the theme, the theme of created message will be the same as its `n-message-provider`. ```vue ``` ### Multiple line ```vue ``` ### Placement ```vue ``` ### Customize message Some users said that they want to use alert as message. ```vue ``` ### No icon ```vue ``` ## API ### MessageProvider Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | closable | `boolean` | `false` | Whether to show close icon on all messages. | | | container-class | `string` | `undefined` | Message container class. | 2.36.0 | | container-style | `string \| CSSProperties` | `undefined` | Message container style. | | | duration | `number` | `3000` | Default duration of on all messages. | | | keep-alive-on-hover | `boolean` | `false` | Whether to destroy while hovering on all messages. | | | max | `number` | `undefined` | Limit the number of messages to display. | | | placement | `top \| top-left \| top-right \| bottom \| bottom-left \| bottom-right ` | `top` | Placement of all messages. | | | to | `string \| HTMLElement` | `'body'` | Container node of message container. | | ### MessageProvider Injection API #### MessageProvider Injection Methods | Name | Type | Description | Version | | --- | --- | --- | --- | | destroyAll | `() => void` | Destroy all popup messages. | | | create | `(content: string \| (() => VNodeChild), option?: MessageOption) => MessageReactive` | Use create type message. | 2.25.7 | | error | `(content: string \| (() => VNodeChild), option?: MessageOption) => MessageReactive` | Use error type message. | | | info | `(content: string \| (() => VNodeChild), option?: MessageOption) => MessageReactive` | Use info type message. | | | loading | `(content: string \| (() => VNodeChild), option?: MessageOption) => MessageReactive` | Use loading type message. | | | success | `(content: string \| (() => VNodeChild), option?: MessageOption) => MessageReactive` | Use success type message. | | | warning | `(content: string \| (() => VNodeChild), option?: MessageOption) => MessageReactive` | Use warning type message. | | #### MessageOption Properties | Name | Type | Description | Version | | --- | --- | --- | --- | | closable | `boolean` | Whether to show close icon. | | | duration | `number` | The duration of the message. | | | icon | `() => VNodeChild` | Message icon. | | | keepAliveOnHover | `boolean` | Messages whether to destroy while hover. | | | render | `MessageRenderMessage` | Render function of the entire message. | 2.24.0 | | showIcon | `boolean` | Whether to show icon. | 2.25.7 | | spinProps | `{ strokeWidth?: number, stroke?: string, scale?: number, radius?: number }` | Loading icon properties. | 2.44.0 | | type | `'info' \| 'success' \| 'warning' \| 'error' \| 'loading' \| 'default'` | Message type. | `'default'` 2.25.7 | | onAfterLeave | `() => void` | Callback after message disappeared. | | | onClose | `() => void` | Callback when close icon is clicked. | | | onLeave | `() => void` | Callback when message start to disappear. | | #### MessageRenderMessage Type ```ts type MessageRenderMessage = (props: { content?: string | number | (() => VNodeChild) icon?: () => VNodeChild closable: boolean type: 'info' | 'success' | 'warning' | 'error' | 'loading' onClose?: () => void }) => VNodeChild ``` #### MessageReactive Properties | Name | Type | Description | Version | | --- | --- | --- | --- | | closable | `boolean` | Whether to show close icon. | | | content | `string \| (() => VNodeChild)` | Message content. | | | destroy | `() => void` | Message destroy method. | | | icon | `() => VNodeChild` | Message icon. | | | keepAliveOnHover | `boolean` | Messages whether to destroy while hover | | | showIcon | `boolean` | Whether to show icon. | 2.25.7 | | type | `'info' \| 'success' \| 'warning' \| 'error' \| 'loading' \| 'default'` | Message type. | `'default'` 2.25.7 | | onAfterLeave | `() => void` | Callback after message disappeared. | | | onLeave | `() => void` | Callback when message start to disappear. | | #### MessageReactive Methods | Name | Type | Description | | ------- | ---- | ----------------------- | | destroy | `()` | Message destroy method. | ## Q & A ### Use Message Outside Setup #### Option 1 Use [createDiscreteApi](https://www.naiveui.com/en-US/components/discrete.md). If you want to use it, read its caveat carefully. You'd better not use `useMessage` and it together in a same app. #### Option 2 > You need to mount the return value of `useMessage` to the window in the top-level setup and then call it. Before calling it, you need to make sure that message has been mounted successfully. ```html ``` ```html ``` ```js // xxx.js export function handler() { // You need to ensure that window.$message = message has been executed in setup window.$message.success( 'Cause you walked hand in hand With another man in my place' ) } ``` --- # Modal It just pops and shows you something. > **Notice** > > - If you want to use `useModal` to create modal, you need to put the component that calls its method inside `n-modal-provider` and use `useModal` to get the API. > - If you want to know how to use it outside of `setup`, please refer to Q & A at the bottom of this page. For example: ```html ``` ```js import { useModal } from 'naive-ui' import { defineComponent } from 'vue' // content export default defineComponent({ setup() { const modal = useModal() return { showModal() { modal.create({ title: 'Title', content: 'Content' }) } } } }) ``` ## Demos ### Basic Basic usage of modal. You can put anything in modal, a card for example. ```vue ``` ### Content Scrollable When using the Card preset, enable `content-scrollable` to keep scrolling inside the content area only. The header and footer stay fixed. ```vue ``` ### Imperative API Provided since `2.38.0`. You can use `useModal.create` to create a modal. (Please make sure this API is called inside `n-modal-provider`.) ```vue ``` ### Controlled Modal can be controlled. ```vue ``` ### Mask closable Use `mask-closable=false` to make modal not emit the event which may close the modal. ```vue ``` ### Customizing position Use fixed position to set the position of the modal. ```vue ``` ### Use preset card Modal has some presets, which means you can use props & slots of the preset after set it. ```vue ``` ### Use preset dialog An example of preset `dialog`. ```vue ``` ### Use preset dialog (slot) Slots are also related to preset. ```vue ``` ### Transform origin Although the emerging animation from your click position is cool, sometimes we need a plain animation which occurs from the center of the screen. You can set `transfrom-origin` to `'center'` to achieve it. ```vue ``` ### Draggable Set `draggable` to `true` to make modal draggable. If you want it to be dragged out of the window, you can set `draggable` to `{ bounds: 'none' }`. If you want to completely customize the content of the modal, you can use the `draggableClass` in the `default` slot to set it on the element you want to trigger the drag. ```vue ``` ### Mask visible You can also hide the modal dialog's mask layer, which allows creating a floating panel. Note that in this case, all mask-related APIs will be disabled, focus won't be limit inside modal (so keyboard event like Esc won't always work). ```vue ``` ## API ### ModalProvider Props Provided since `2.38.0`. | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | to | `string \| HTMLElement` | `body` | Container node of the modal content. | 2.38.0 | ### useModal API Provided since `2.38.0`. | Name | Type | Description | Version | | --- | --- | --- | --- | | create | `(options: ModalOptions) => ModalReactive` | Create a modal. | 2.38.0 | | destroyAll | `() => void` | Destroy all modals. | 2.38.0 | `ModalOptions` and `ModalReactive`'s properties are the same as `ModalProps` (properties should use camelCase, for example `auto-focus` property should use `autoFocus` as option property). ### Modal Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | auto-focus | `boolean` | `true` | Whether to focus the first focusable element inside modal. | 2.24.2 | | block-scroll | `boolean` | `true` | Whether to disabled body scrolling when it's active. | 2.28.3 | | close-on-esc | `boolean` | `true` | Whether to close modal on Esc is pressed. | 2.24.2 | | display-directive | `'if' \| 'show'` | `'if'` | Use which directive to control the rendering of modal body. | | | draggable | `boolean \| { bounds?: 'window' }` | `false` | Whether the modal is draggable. Make its position not bound inside window using `bounds === 'none'`. | 2.41.0 | | mask-closable | `boolean` | `true` | Whether to emit `hide` event when click mask. | | | preset | `'dialog' \| 'card'` | `undefined` | The preset of `n-modal`. | | | show | `boolean` | `false` | Whether to show modal. | | | show-mask | `boolean` | `true` | Whether to display the mask. If it's set to `false`, all mask-related APIs will be disabled, focus won't be limit inside modal (so keyboard event like Esc won't always work). | 2.43.0 | | to | `string \| HTMLElement` | `body` | Container node of the modal content. | | | transform-origin | `'mouse' \| 'center'` | `'mouse'` | The transform origin of the modal's display animation. | | | trap-focus | `boolean` | `true` | Whether to trap focus inside modal. | 2.24.2 | | z-index | `number` | `undefined` | Z index of the modal. | 2.24.0 | | on-after-enter | `() => void` | `undefined` | Callback after modal is opened. | | | on-after-leave | `() => void` | `undefined` | Callback after modal is closed. | | | on-esc | `() => void` | `undefined` | Callback fired when the escape key is pressed and focus is within modal. | 2.24.2 | | on-mask-click | `() => void` | `undefined` | Callback on mask is clicked. | | | on-update:show | `(value: boolean) => void` | `undefined` | Callback when modal's display status is changed. | | ### ModalProvider Props Provided since 2.38.0. | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | to | `string \| HTMLElement` | `body` | Container node of the modal content. | 2.38.0 | ### Modal with Preset Card Props See [Card props](https://www.naiveui.com/en-US/components/card.md#Card-Props) ### Modal with Preset Dialog Props See [Dialog props](https://www.naiveui.com/en-US/components/dialog.md#Dialog-Props) ### Modal without Preset Slots | Name | Parameters | Description | | ------- | ---------- | ------------------------- | | default | `()` | The content of the modal. | ### Modal with Preset Card Slots See [Card slots](https://www.naiveui.com/en-US/components/card.md#Card-Slots) `default` slot's parameter is different, which is `(props: { draggableClass: string })`. ### Modal with Preset Dialog Slots See [Dialog slots](https://www.naiveui.com/en-US/components/dialog.md#Dialog-Slots) `default` slot's parameter is different, which is `(props: { draggableClass: string })`. ## Q & A ### Use Modal Outside Setup #### Option 1 Use [createDiscreteApi](https://www.naiveui.com/en-US/components/discrete.md). If you want to use it, read its caveat carefully. You'd better not use `useModal` and it together in a same app. #### Option 2 > You need to mount the return value of `useModal` to the window in the top-level setup and then call it. Before calling it, you need to make sure that modal has been mounted successfully. ```html ``` ```html ``` ```js // xxx.js export function handler() { // You need to ensure that window.$modal = modal has been executed in setup window.$modal.create({ title: 'Title', content: 'Content' }) } ``` --- # Notification If something is to be telled to somebody. Notification component is always with low piority so I can make a lot of useless animations on it. > **Prerequisite** > > If you want to use notification, you need to wrap the component where you call related methods inside `n-notification-provider` and use `useNotification` to get the API. For example: ```html ``` ```js import { useNotification } from 'naive-ui' import { defineComponent } from 'vue' // content export default defineComponent({ setup() { const notification = useNotification() return { warning() { notification.warning({ content: '...' }) } } } }) ``` ## Demos ### Basic ```vue ``` ### Type ```vue ``` ### Change Content Dynamically You can change any parts of notifications existed. ```vue ``` ### Scrollable Change the property will cause all existing notifications to be cleaned, so please make sure you change this property at proper time. ```vue ``` ### Unclosable You can make it unclosable. ```vue ``` ### Duration Auto close. ```vue ``` ### Max ```vue ``` ### Placement ```vue ``` ## API ### NotificationProvider Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | container-class | `string` | `undefined` | Class of notification container. | 2.36.0 | | container-style | `string \| Object` | `undefined` | Style of notification container. | 2.25.0 | | placement | `'top' \| 'bottom' \|'top-right' \| 'top-left' \| 'bottom-left' \| 'bottom-right'` | `'top-right'` | Placement of all notifications. | `'top' \| 'bottom'` 2.29.0 | | max | `number` | `undefined` | Limit the number of notifications to display. | | | scrollable | `boolean` | `true` | Whether notification can be scroll. Unavailable when `placement` equals `'top'` or `'bottom'`. | | | to | `string \| HTMLElement` | `'body'` | Container node of notification container. | | ### notification Injection Methods | Name | Type | Description | | --- | --- | --- | | create | `(option: NotificationOption) => NotificationReactive` | Create a notification. | | destroyAll | `() => void` | Destroy all popup notifications. | | error | `(option: NotificationOption) => NotificationReactive` | Use `error` type notification. | | info | `(option: NotificationOption) => NotificationReactive` | Use `info` type notification. | | success | `(option: NotificationOption) => NotificationReactive` | Use `success` type notification. | | warning | `(option: NotificationOption) => NotificationReactive` | Use `warning` type notification. | ### NotificationOption Properties | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | action | `string \| (() => VNodeChild)` | `undefined` | Content of the operation area,, can be a render function. | | | avatar | `() => VNodeChild` | `undefined` | Content of the `avatar`. | | | closable | `boolean` | `true` | Whether to show close icon. | | | content | `string \| (() => VNodeChild)` | `undefined` | Content, can be a render function. | | | description | `string \| (() => VNodeChild)` | `undefined` | Content of the `description`, can be a render function. | | | duration | `number` | `undefined` | If not set, it won't automatically close. Unit is millisecond. | | | keepAliveOnHover | `boolean` | `false` | Whether to keep the notification when mouse hover. | 2.32.0 | | meta | `string \| (() => VNodeChild)` | `undefined` | Content of the `meta`, can be a render function. | | | title | `string \| (() => VNodeChild)` | `undefined` | Content of the `title`, can be a render function. | | | onAfterEnter | `Function` | `undefined` | Callback triggered after Transition's enter animation executed. | | | onAfterLeave | `Function` | `undefined` | Callback triggered after Transition's leave animation executed. | | | onClose | `() => boolean \| Promise` | `undefined` | The callback of notification closing. Returning `false`, promise resolve `false` or promise reject will cancel this closing. | | | onLeave | `Function` | `undefined` | Callback triggered when Transition's leave animation executed. | | ### NotificationReactive API #### NotificationReactive Properties Properties of NotificationReactive can be dynamically changed. | Name | Type | Description | | --- | --- | --- | | action | `string \| (() => VNodeChild)` | Content of the operation area,, can be a render function. | | avatar | `() => VNodeChild` | Content of the `avatar`, can be a render function. | | closable | `boolean` | Whether to show close icon. | | content | `string \| (() => VNodeChild)` | Content, can be a render function. | | description | `string \| (() => VNodeChild)` | Content of the `description`, can be a render function. | | duration | `number` | If not set, it won't automatically close. Unit is millisecond. | | meta | `string \| (() => VNodeChild)` | Content of the `meta`, can be a render function. | | title | `string \| (() => VNodeChild)` | Content of the `title`, can be a render function. | | onAfterEnter | `Function` | Callback triggered after Transition's enter animation executed. | | onAfterLeave | `Function` | Callback triggered after Transition's leave animation executed. | | onClose | `() => boolean \| Promise` | The callback of notification closing. Returning `false`, promise resolve `false` or promise reject will cancel this closing. | | onLeave | `Function` | Callback triggered when Transition's leave animation executed. | #### NotificationReactive Methods | Name | Type | Description | | ------- | ---- | ------------------------- | | destroy | `()` | Destroy the notification. | --- # Popconfirm A confirm, poped. ## Demos ### Basic ```vue ``` ### Custom Action ```vue ``` ### Custom Icon ```vue ``` ### Event `positive-click` & `negative-click` ```vue ``` ### No icon ```vue ``` ### Actions ```vue ``` ## API ### Popconfirm Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | negative-button-props | `ButtonProps` | `undefined` | Cancel button's DOM props | 2.27.0 | | negative-text | `string \| null` | `'Cancel'` | Cancel button text. | 2.28.0 | | positive-button-props | `ButtonProps` | `undefined` | Confirm button's DOM props | 2.27.0 | | positive-text | `string \| null` | `'Confirm'` | Confirm button text. | 2.28.0 | | show-icon | `boolean` | `true` | Whether to show icon. | | | on-positive-click | `() => boolean \| Promise \| any` | `undefined` | Callback of confirmation. | | | on-negative-click | `() => boolean \| Promise \| any` | `undefined` | Callback of cancel. | | For more props, see [popover](https://www.naiveui.com/en-US/components/popover.md#Popover-Props). ### Popconfirm Slots | Name | Parameters | Description | | ------- | ---------- | ------------------- | | action | `()` | Custom action. | | default | `()` | Popconfirm content. | | icon | `()` | Popconfirm icon. | ### Popconfirm Methods See [popover](https://www.naiveui.com/en-US/components/popover.md#Popover-Methods). --- # Popover Pop some hidden message around content. There isn't much builtin styles in popover. It's more up to you to fill the content. If you just want to display some basic text message, see [Tooltip](https://www.naiveui.com/en-US/components/tooltip.md) instead. ## Demos ### Basic ```vue ``` ### Trigger ```vue ``` ### Delay ```vue ``` ### No arrow ```vue ``` ### Event ```vue ``` ### Placement ```vue ``` ### Raw content ```vue ``` ### Style You can use `style` to set popover's style. You can set `scrollable` to make popover's content scrollable. If popover is scrollable, You can use `content-style` to set popover's content style. ```vue ``` ### Use trigger width Set `width="trigger"` to make popover's width the same as its trigger. ```vue ``` ### Manually positioned Warn: when manually positioned, the `trigger` prop must be `'manual'`. ```vue ``` ### Slots Use `header` or `footer` slot to customize header or footer. ```vue ``` ## API ### Popover Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | animated | `boolean` | `true` | Use animation when popping up. | | | arrow-point-to-center | `boolean` | `false` | Whether the arrow points to center of the trigger element. | 2.26.0 | | arrow-class | `string` | `undefined` | Arrow class of the popover. | 2.36.0 | | arrow-style | `string \| Object` | `undefined` | Arrow style of the popover. | | | arrow-wrapper-class | `string` | `undefined` | Arrow class of the popover wrapper. | 2.36.0 | | arrow-wrapper-style | `string \| Object` | `undefined` | Arrow style of the popover wrapper. | 2.36.0 | | content-class | `string` | `undefined` | Content class of the popover. | 2.36.0 | | content-style | `string \| Object` | `undefined` | Content style of the popover. | 2.28.3 | | delay | `number` | `100` | Popover showing delay when trigger is `hover`. | | | disabled | `boolean` | `false` | Whether the popover can't be activated. | | | display-directive | `'if' \| 'show'` | `'if'` | The conditionally render directive to show popover content. `if` means using `v-if` to render content, `show` means using `v-show` to render content. | | | duration | `number` | `100` | Popover vanish delay when trigger is `hover`. | | | flip | `boolean` | `true` | Whether to flip the popover when there is no space for current placement. | | | footer-class | `string` | `undefined` | Footer class of the popover. | 2.36.0 | | footer-style | `string \| Object` | `undefined` | Footer style of the popover. | 2.31.0 | | header-class | `string` | `undefined` | Header class of the popover. | 2.36.0 | | header-style | `string \| Object` | `undefined` | Header style of the popover. | 2.28.3 | | keep-alive-on-hover | `boolean` | `true` | Whether to keep popover shown when hover on popover itself with `trigger="hover"`. | 2.25.0 | | overlap | `boolean` | `false` | Overlap trigger element. | | | placement | `'top-start' \| 'top' \| 'top-end' \| 'right-start' \| 'right' \| 'right-end' \| 'bottom-start' \| 'bottom' \| 'bottom-end' \| 'left-start' \| 'left' \| 'left-end' \| ` | `'top'` | Popover placement. | | | raw | `boolean` | `false` | Whether to use no default styles. | | | scrollable | `boolean` | `false` | Whether the popover's content is scrollable. | 2.28.3 | | show-arrow | `boolean` | `true` | Whether to show arrow if set. | | | show | `boolean` | `undefined` | Whether to show popover. | | | to | `string \| HTMLElement \| false` | `'body'` | Container node of the popover content. `false` will keep it at trigger container. | | | trigger | `'hover' \| 'click' \| 'focus' \| 'manual'` | `'hover'` | The popover trigger type. | | | width | `number \| 'trigger'` | `undefined` | `'trigger'` means popover's width will follow its trigger's width. | | | x | `number` | `undefined` | The CSS `left` pixel value when popover manually positioned (x, y need to be set together). | | | y | `number` | `undefined` | The CSS `top` pixel value when popover manually positioned (x, y need to be set together). | | | z-index | `number` | `undefined` | The z-index of the popover. | | | on-clickoutside | `(e: MouseEvent) => void` | `undefined` | Callback function triggered when clickoutside. | | | on-update:show | `(value: boolean) => void` | `undefined` | Callback on show status changes. | | ### Popover Slots | Name | Parameters | Description | Version | | --- | --- | --- | --- | | trigger | `()` | The element or component that triggers popover. | | | footer | `()` | The footer content of the popover. | 2.31.0 | | header | `()` | The header content of the popover. | 2.28.3 | | default | `()` | The content inside popover. | | ### Popover Methods | Name | Parameters | Description | | ------------ | ----------------- | ------------------------------------- | | setShow | `(show: boolean)` | Set show status in uncontrolled mode. | | syncPosition | `()` | Sync popover position. | --- # Popselect If you want select some options but don't want a picker, you can use popselect instead. ## Demos ### Basic ```vue ``` ### Size ```vue ``` ### Scrollable ```vue ``` ### Multiple Select multiple value in popselect. ```vue ``` ### Slot Is there anybody who needs slots in a select menu? ```vue ``` ## API ### Popselect Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | multiple | `boolean` | `false` | Whether to select multiple values. | | | node-props | `(option: SelectOption \| SelectGroupOption) => object` | `undefined` | Option's DOM attrs generator. | 2.30.4 | | options | `Array` | `[]` | For details of configuration options, see [Select](https://www.naiveui.com/en-US/components/select.md#SelectOption-Properties) | | | render-label | `(option: SelectOption \| SelectGroupOption) => VNodeChild` | `undefined` | Render function of all the options. | | | scrollable | `boolean` | `false` | Whether the select menu is scrollable. | | | scrollbar-props | `ScrollbarProps` | `undefined` | See [Scrollbar props](https://www.naiveui.com/en-US/components/scrollbar.md#Scrollbar-Props) | 2.44.0 | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | Size of the Popselect. | | | value | `string \| number \| Array \| null` | `null` | Value in controlled mode. | | | virtual-scroll | `boolean` | `false` | Whether to enable virtual scrolling. | 2.30.4 | | on-update:value | `(value: string \| number \| Array \| null, option: SelectBaseOption \| null \| Array) => void` | `undefined` | Callback of value updating. | | For SelectOption & SelectGroupOption, see [Select](https://www.naiveui.com/en-US/components/select.md#SelectOption-Properties) For other props, see [Popover](https://www.naiveui.com/en-US/components/popover.md#Popover-Props) ### Popselect Slots | Name | Parameters | Description | Version | | ------ | ---------- | -------------------------------------- | ------- | | header | `()` | Header menu slot. | 2.36.0 | | action | `()` | Options menu slot. | 2.22.0 | | empty | `()` | Empty state slot for the options menu. | 2.22.0 | --- # Progress I have no words to say but there still should be a placeholder to make layout looks spread. ## Demos ### Circle Progress can be a circle. It can be `default`, `info`, `success`, `warning` or `error` status. ```vue ``` ### Line In fact, progress of line type don't need four different styles. However, since UI has designed it, I finally implemented them all. It also support `default`, `info`, `success`, `warning` or `error` status. ```vue ``` ### Offset Circular progress can have `offset-degree`. ```vue ``` ### Multiple circle Maybe your product manager will need it. ```vue ``` ### Dashboard Maybe you also need `gap-degree` and `gap-offset-degree` properties to customize the dashboard. ```vue ``` ### Custom indicator You can custom the indicator. ```vue ``` ### Customize color If you are not satisfied with builtin colors. ```vue ``` ### No indicator If you don't want indicator. ```vue ``` ### Height & border radius In case you aren't satisfied with height & border-radius. ```vue ``` ### Processing ```vue ``` ### Linear Gradient You may want to use color combinations. ```vue ``` ## API ### Progress Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | border-radius | `number \| string` | `undefined` | `'line'` typed progress's border-radius. Keep half of default height if not passed. | | | circle-gap | `number` | `1` | The gap between circles when type is `'multiple-circle'`, suppose `viewbox` size is `100`. | | | color | `string \| string[] \| { stops: string[] } \| Array<{ stops: string[] }>` | `undefined` | Progress color. `{ stops: string[] }` indicates a gradient color. `stops` array must have length of 2. The first element is gradient start color. The second element is gradient end color. | `stops` since 2.40.2 | | fill-border-radius | `number \| string` | `undefined` | `'line'` typed progress's fill's border-radius. Keep `border-radius` if not passed. | | | gap-degree | `number` | `75` | The gap degree of half circle, 0 ~ 360. | 2.25.2 | | gap-offset-degree | `number` | `0` | The gap offset degree. | 2.25.2 | | height | `number` | `undefined` | `'line'` typed progress's height. Keep default height if not passed. | | | indicator-placement | `'inside' \| 'outside'` | `'outside'` | Indicator placement. | | | indicator-text-color | `string` | `undefined` | Indicator text color. | | | offset-degress | `number` | `0` | Offset degree of circular progress, only works with `circle` typed progress. | 2.24.0 | | percentage | `number \| number[]` | `0` | Percentage value. | | | processing | `boolean` | `false` | Processing status. | | | rail-color | `string \| string[]` | `undefined` | Rail color. | | | rail-style | `string \| CSS \| Array` | `undefined` | Rail style. | | | show-indicator | `boolean` | `true` | Whether to display indicators. | | | status | `'default' \| 'success' \| 'error' \| 'warning' \| 'info'` | `'default'` | Progress status. | | | stroke-width | `number` | `7` | Progress width. | | | type | `'line' \| 'circle' \| 'multiple-circle' \| 'dashboard'` | `line` | Progress type. | `'dashboard'` 2.25.2 | | unit | `string` | `%` | Progress unit. | | ### Progress Slots | Name | Parameters | Description | | ------- | ---------- | ----------------------------------------------- | | default | `()` | Content will replace default indicator content. | --- # Result Result is for showing result. Many thanks to [twemoji](https://github.com/twitter/twemoji) for creating those high quality icons. ## Demos ### 404 ```vue ``` ### 403 ```vue ``` ### 500 ```vue ``` ### 418 ```vue ``` ### Info ```vue ``` ### Success ```vue ``` ### Warning ```vue ``` ### Error ```vue ``` ### Size ```vue ``` ### Customizing icon Put whatever you like inside. ```vue ``` ## API ### Result Props | Name | Type | Default | Description | | --- | --- | --- | --- | | description | `string` | `undefined` | Description. | | size | `'small' \| 'medium' \| 'large' \| 'huge'` | `'medium'` | Size. | | status | `'info' \| 'success' \| 'warning' \| 'error' \| '404' \| '403' \| '500' \| '418'` | `'info'` | Status. | | title | `string` | `undefined` | Title. | ### Result Slots | Name | Parameters | Description | Version | | --- | --- | --- | --- | | default | `()` | Results page content information. | | | footer | `()` | Information at the bottom of the results page. | | | icon | `()` | Custom icon content area. | 2.24.0 | --- # Skeleton A twinkle placeholder. ## Demos ### Basic usage Use `text` to create text skeleton. ```vue ``` ### Box Use it as a box. ```vue ``` ### Size Use `size` to make its height the same as other components. ```vue ``` ## API ### Skeleton Props | Name | Type | Default | Description | | --- | --- | --- | --- | | text | `boolean` | `false` | Text skeleton. | | round | `boolean` | `false` | Round skeleton. | | circle | `boolean` | `false` | Circle skeleton. | | height | `string \| number` | `undefined` | Skeleton height. | | width | `string \| number` | `undefined` | Skeleton width. | | size | `'small' \| 'medium' \| 'large'` | `undefined` | Skeleton size. | | repeat | `string \| number` | `1` | Repeat frequency. | | animated | `boolean` | `true` | Whether to enable animation. | | sharp | `boolean` | `true` | Whether to display as a right angled skeleton. | --- # Spin It could've been called `loading`, but why is it called `spin`? Because there is another internal component with less props already named `loading`. ## Demos ### Basic Here are `small`, `medium` and `large` spins. ```vue ``` ### Wrap You can wrap a component inside spin. ```vue ``` ### Description You can add some description under the spin. ```vue ``` ### Customize icon ```vue ``` ### Delay You can specify a delay for displaying spin. If spinning ends during delay, spin won't appear. ```vue ``` ## API ### Spin Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | content-class | `string` | `undefined` | Content Class of the spin. | 2.36.0 | | content-style | `string \| Object` | `undefined` | Content style of the spin. | 2.36.0 | | description | `string` | `undefined` | Description of the spin. | | rotate | `boolean` | `true` | Specify whether icon rotates, only working for custom icon. | | size | `'small' \| 'medium' \| 'large' \| number` | `'medium'` | Size of the spin. | | show | `boolean` | `true` | Specify whether spin is active when spin has content inside. It won't work if you just use spin itself. | | stroke-width | `number` | `undefined` | Relative width of spin's stroke, assuming the outer radius of spin is 100. | | radius | `number` | `100` | Outer radius of the spin icon. | 2.44.0 | | scale | `number` | `1` | Scale factor of the spin icon. | 2.44.0 | | stroke | `string` | `undefined` | Color of the spin. | | delay | `number` | `undefined` | Specifies a delay in milliseconds for loading state (prevent flush). | ### Spin Slots | Name | Parameters | Description | | ----------- | ---------- | ----------------------------------- | | default | `()` | If set, spin will wrap the content. | | description | `()` | Description of the spin. | | icon | `()` | Customize the spin icon. | --- # Tooltip It walks like a popover, quacks like a popover but looks a bit different from popover. ## Demos ### Basic ```vue ``` ### Trigger ```vue ``` ### Event ```vue ``` ### Placement ```vue ``` ### Body style Setting style is sometimes useful. ```vue ``` ### No arrow ```vue ``` ## API ### Tooltip Props See [Popover Props](https://www.naiveui.com/en-US/components/popover.md#Popover-Props) ### Tooltip Slots See [Popover Slots](https://www.naiveui.com/en-US/components/popover.md#Popover-Slots) --- # Flex Available since `2.37.0`. Frankly saying, it functions similarly to `n-space`. However use `n-flex` if possible. `n-flex` utilizes the flex layout, and note that the gap property might have compatibility issues with some older browsers. On the other hand, `n-space` involves operations at the `VNode` level, which could lead to rendering issues in certain specific use cases. ## Demos ### Basic ```vue ``` ### Vertical ```vue ``` ### From End ```vue ``` ### Space Between ```vue ``` ### Space Around ```vue ``` ### From Center ```vue ``` ## API ### Flex Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | align | `string` | `undefined` | Way to align items, see [align-items](https://developer.mozilla.org/zh-CN/docs/Web/CSS/align-items). | 2.37.0 | | inline | `boolean` | `false` | Whether it's display is `inline-flex`. | 2.37.0 | | justify | `string` | `'start'` | Way to justify content, see [justify-content](https://developer.mozilla.org/zh-CN/docs/Web/CSS/justify-content). | 2.37.0 | | size | `'small' \| 'medium' \| 'large' \| number \| [number, number]` | `'medium'` | When it's a number, it will be used as vertical and horizontal gap, or it is `[horizontalGap, verticalGap]`. | 2.37.0 | | vertical | `boolean` | `false` | Whether to layout content vertically. | 2.37.0 | | wrap | `boolean` | `true` | Whether to wrap content if `n-flex`'s width is exceeded. | 2.37.0 | ### Flex Slots | Name | Parameters | Description | Version | | ------- | ---------- | ---------------- | ------- | | default | `()` | Spacing content. | 2.37.0 | --- # Layout Layout is for layout. The component is a bit complicated to use. But like a manual gear car, it worths a shot. If you are use version before v2.3.0, you may want to know about [Changes After v2.3.0](#Changes-After-v2.3.0). ## Demos ### Basic I hope the demo can meet you demand, so that you can have more time to do other things. ```vue ``` ### About setting padding If you still want to do so, please make sure you know about their DOM structure. ```vue ``` ### Border You can set `bordered` on sider、footer、header. ```vue ``` ### Embedded effect Sometimes you may want the background to be darker to highlight the content (especially card like things). ```vue ``` ### Absolute position All layout components can use absolute positioning. It can be used when you want content scrolling inside fixed area. ```vue ``` ### Use built-in scrollbar Sometimes you will find native scrollbar doesn't meet the style of naive-ui. You can use built-in scrollbar of naive-ui (on `n-layout-sider`, `n-layout` or `n-content`). ```vue ``` ### Collapse sider Use `show-trigger` to use builtin button. ```vue ``` ### Sider placement Sometimes you might want to put the collapsed sidebar on the right. ```vue ``` ### Inverted Use `inverted` to add contrast. You can set the prop on header, footer and sider. Usually used with menu. ```vue ``` ### Hide sider content Sometimes you don't want to see content inside sider after it's collapsed. Set `show-collapsed-content` to `false` on sider. ```vue ``` ### Scroll to ```vue ``` ## API ### Layout, Layout Content Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | content-class | `string` | `undefined` | Class of scrollable content node. | 2.36.0 | | content-style | `string \| Object` | `undefined` | Style of scrollable content node. | | | embedded | `boolean` | `false` | Use darker background to show a embedded effect. Only work for light theme. | | | has-sider | `boolean` | `false` | Whether the component has sider inside. If so it must be `true`. | | | native-scrollbar | `boolean` | `true` | Whether to use native scrollbar on itself. If set to `false`, layout will use a naive-ui style scrollbar for content. | | | position | `'static' \| 'absolute'` | `'static'` | `static` position will make it css position set to `static`. `absolute` position will make it css position set to `absolute` and `left`, `right`, `top`, `bottom` to `0`. `absolute` position is very useful when you want to make content scroll in a fixed container or make the whole page's layout in a fixed position. You may need to change the style of the component to make it display as you expect. | | | scrollbar-props | `ScrollbarProps` | `undefined` | See [Scrollbar props](https://www.naiveui.com/en-US/components/scrollbar.md#Scrollbar-Props). | | | sider-placement | `'left' \| 'right'` | `left` | The sidebar is displayed on the left or the right side. | | | on-scroll | `(e: Event) => void` | `undefined` | Callback function when the content scroll. | | ### Layout Footer Props | Name | Type | Default | Description | | --- | --- | --- | --- | | bordered | `boolean` | `false` | Whether to show the border. | | inverted | `boolean` | `false` | Whether to use inverted background. | | position | `'static' \| 'absolute'` | `'static'` | `static` position will make it css position set to `static`. `absolute` position will make it css position set to `absolute` and `left`, `right`, `top` to `0`. `absolute` position is very useful when you want to make content scroll in a fixed container or make the whole page's layout in a fixed position. You may need to change the style of the component to make it display as you expect. | ### Layout Header Props | Name | Type | Default | Description | | --- | --- | --- | --- | | bordered | `boolean` | `false` | Whether to show the border. | | inverted | `boolean` | `false` | Whether to use inverted background. | | position | `'static' \| 'absolute'` | `'static'` | `static` position will make it css position set to `static`. `absolute` position will make it css position set to `absolute` and `left`, `right`, `bottom` to `0`. `absolute` position is very useful when you want to make content scroll in a fixed container or make the whole page's layout in a fixed position. You may need to change the style of the component to ma ke as you expect. | ### Layout Sider Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | bordered | `boolean` | `false` | Whether to show the border. | | | collapse-mode | `'transform' \| 'width'` | `'transform'` | If set to `'width'`, the sider's content width will be actually collapsed. If set to `'transform'`, the sider will only move it's position and won't change its content width. | | | collapsed | `boolean` | `undefined` | Whether the sider is collapsed. It only works for when `position` is `'static'`. | | | collapsed-trigger-class | `string` | `undefined` | Trigger class when collapsed. | 2.36.0 | | collapsed-trigger-style | `string \| Object` | `undefined` | Trigger style when collapsed. | | | collapsed-width | `number` | `48` | Folded width. | | | content-class | `string` | `undefined` | Class of scrollable content node. | | | content-style | `string \| Object` | `undefined` | Style of scrollable content node. | | | default-collapsed | `boolean` | `false` | Default collapsed state in uncontrolled mode. | | | inverted | `boolean` | `false` | Whether to use inverted background. | | | native-scrollbar | `boolean` | `true` | Whether to use native scrollbar on itself. If set to `false`, sider will use a naive-ui style scrollbar for content. | | | position | `'static' \| 'absolute'` | `'static'` | `static` position will make it css position set to `static`. `absolute` position will make it css position set to `absolute` and `left`, `top`, `bottom` to `0`. `absolute` position is very useful when you want to make content scroll in a fixed container or make the whole page's layout in a fixed position. You may need to change the style of the component to make it as you expect. | | | scrollbar-props | `ScrollbarProps` | `undefined` | See [Scrollbar props](https://www.naiveui.com/en-US/components/scrollbar.md#Scrollbar-Props). | | | show-collapsed-content | `boolean` | `true` | Whether to show content in sider after it is collapsed. | | | show-trigger | `boolean \| 'bar' \| 'arrow-circle'` | `false` | Whether to show the built-in trigger button on sider. | | | trigger-class | `string` | `undefined` | Trigger class. | 2.36.0 | | trigger-style | `string \| Object` | `undefined` | Trigger style. | | | width | `number \| string` | `272` | Width CSS value. When it is number, px will be added. | | | on-after-enter | `() => void` | `undefined` | Callback after it's expanded. | | | on-after-leave | `() => void` | `undefined` | Callback after it's collapsed. | | | on-scroll | `(e: Event) => void` | `undefined` | Callback function when the content scroll. | | | on-update:collapsed | `(collapsed: boolean) => void` | `undefined` | Callback function when the folding state changes. | | ### Layout, Layout Content, Layout Sider, Layout Header, Layout Footer Slots | Name | Parameters | Description | | ------- | ---------- | --------------- | | default | `()` | Layout content. | ### Layout, Layout Content, Layout Sider Methods | Name | Type | Description | | --- | --- | --- | | scrollTo | `((xCoord: number, yCoord: number) => void) \| (options: { left?: number, top?: number, behavior: 'smooth' \| 'auto' }) => void` | Scroll to somewhere. | ## Changes After v2.3.0 Due to concerns about performance and SSR, after v2.3.0 you need to specify `has-sider` on the `n-layout` which contains `n-layout-sider`. Collapsing won't work for `n-layout-sider` with `position="absolute"`. ```html Before v2.3.0: After v2.3.0: ``` --- # Legacy Grid > **Caveat** > > At most of time you should use [Grid](https://www.naiveui.com/en-US/components/grid.md). A basic grid system. ## Demos ### Basic ```vue ``` ### Gutter Set horizontal gutter & vertical gutter. ```vue ``` ### Offset ```vue ``` ### Push & pull See codes to know what happens. Basically it is relative position change. ```vue ``` ## API ### Row Props | Name | Type | Default | Description | | --- | --- | --- | --- | | gutter | `number \| string \| [number, number] \| [string, string]` | `0` | `horizontal gutter` or `[horizontal gutter, vertical gutter]` | ### Col Props | Name | Type | Default | Description | | ------ | -------- | ------- | ----------- | | span | `number` | `1` | | | offset | `number` | `0` | | | push | `number` | `0` | | | pull | `number` | `0` | | --- # Grid Based on CSS Grid. Responsive. Keep away from IE. > **Caveats** > > Due to technical limitation, `n-grid-item` can't be encapsulated in another component. ## Demos ### Basic `n-grid-item` has an alias called `n-gi`. ```vue ``` ### Gap Set x gap & y gap. ```vue ``` ### Offset ```vue ``` ### Responsive columns You can customize [breakpoints](https://www.naiveui.com/en-US/components/config-provider.md#API) in `n-config-provider`. ```vue ``` ### Responsive grid item When `span` is 0, `n-grid-item` won't be displayed. ```vue ``` ### Collapse Collapsing works in responsive layout. ```vue ``` ### Avoid SSR layout shift By default, `n-grid` will compute grid content based on window size and container size. This would cause 2 side effects: Content may shift in SSR mode; Render items has layout shift and it would influence performance slightly. If you don't need any responsive functionality, you can use `layout-shift-disabled` to get rid of side effects of it. Please note that set `layout-shift-disabled` will disabled all responsive functionality of `n-grid` and `suffix`, `offset` of `n-grid-item`. ```vue ``` ## API ### Grid Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | cols | `number \| ResponsiveDescription` | `24` | Number of grids displayed. | | | collapsed | `boolean` | `false` | Whether to fold by default. | | | collapsed-rows | `number` | `1` | The number of rows displayed by default. | | | layout-shift-disabled | `boolean` | `false` | By default, `n-grid` will compute grid content based on window size and container size. This would cause 2 side effects: Content may shift in SSR mode; Render items has layout shift and it would influence performance slightly. If you don't need any responsive functionality, you can use `layout-shift-disabled` to get rid of side effects of it. Please note that set `layout-shift-disabled` will disabled all responsive functionality of `n-grid` and `suffix`, `offset` of `n-grid-item`. | 2.32.2 | | responsive | `'self' \| 'screen'` | `'self'` | `'self'` triggers responsive layout by its own width. `'screen'` triggers responsive layout by viewport's width. | | | item-responsive | `boolean` | `false` | Whether the grid item is responsive. | | | x-gap | `number \| ResponsiveDescription` | `0` | Horizontal gap. | | | y-gap | `number \| ResponsiveDescription` | `0` | Vertical gap. | | ### GridItem Props | Name | Type | Default | Description | | --- | --- | --- | --- | | offset | `number \| ResponsiveDescription` | `0` | The number of intervals to the left of the grid. | | span | `number \| ResponsiveDescription` | `1` | The number of columns occupied by the grid. The grid item would be hidden if it's 0. | | suffix | `boolean` | `false` | Grid suffix. | ### Grid Slots | Name | Parameters | Description | | ------- | ---------- | ------------- | | default | `()` | Grid content. | ### GridItem Slots | Name | Parameters | Description | | ------- | ------------------------- | ------------------ | | default | `({ overflow: boolean })` | Grid item content. | --- # Space A great invention (which is not invented by me). If you don't have compatibility issues for `gap` CSS property, it's suggested to use [Flex](https://www.naiveui.com/en-US/components/flex.md). ## Demos ### Basic ```vue ``` ### Vertical ```vue ``` ### From End ```vue ``` ### Space Between ```vue ``` ### Space Around ```vue ``` ### From Center ```vue ``` ### Reverse ```vue ``` ## API ### Space Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | align | `'start' \| 'end' \| 'center' \| 'baseline' \| 'stretch'` | `undefined` | Vertical arrangement. | | | inline | `boolean` | `false` | Is it an inline element. | | | wrap-item | `boolean` | `true` | Whether a container exists to wrap the child elements. `false` value will only work in browsers that supports flex gap. | 2.30.5 | | item-class | `string` | `undefined` | Node class, valid when `wrap-item` is `true` | 2.36.0 | | item-style | `string \| object` | `undefined` | Node style, valid when `wrap-item` is `true` | | | justify | `'start' \| 'end' \| 'center' \| 'space-around' \| 'space-between' \| 'space-evenly'` | `'start'` | Horizontal arrangement. | `'space-evenly'` 2.28.3 | | reverse | `boolean` | `false` | Whether to reverse inner items. | 2.37.0 | | size | `'small' \| 'medium' \| 'large' \| number \| [number, number]` | `'medium'` | When it's a number, it will be used as vertical and horizontal gap, or it is `[horizontalGap, verticalGap]`. | | | vertical | `boolean` | `false` | Whether to lay out vertically. | | | wrap | `boolean` | `true` | Whether to exceed the line break. | | ### Space Slots | Name | Parameters | Description | | ------- | ---------- | ---------------- | | default | `()` | Spacing content. | --- # Split The flexible layout tool provides the possibility of customizing the interface layout. Available since `2.36.0`. ## Demos ### Basic ```vue ``` ### Vertical layout ```vue ``` ### Nested layout ```vue ``` ### Event ```vue ``` ### Slot ```vue ``` ### Controlled manner ```vue ``` ## API ### Split Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | default-size | `number` | `0.5` | Default split size, when it's `number` it should in 0 ~ 1, when it's `string` it should be formatted in `${number}px`. | 2.36.0, `string` 2.38.2 | | direction | `'horizontal' \| 'vertical'` | `'horizontal'` | The direction of the split. | 2.36.0 | | disabled | `boolean` | `false` | Whether to disable the split. | 2.36.0 | | max | `string \| number` | `1` | The maximum split threshold, when it's `number` it should in 0 ~ 1, when it's `string` it should be formatted in `${number}px`. | 2.36.0, `string` 2.38.2 | | min | `string \| number` | `0` | The minimum threshold for splitting, when it's `number` it should in 0 ~ 1, when it's `string` it should be formatted in `${number}px`. | 2.36.0, `string` 2.38.2 | | pane1-class | `string` | `undefined` | The class name of the first pane. | 2.38.2 | | pane1-style | `Object \| string` | `undefined` | The Style of the first pane | 2.38.2 | | pane2-class | `string` | `undefined` | The class name of the second pane. | 2.38.2 | | pane2-style | `Object \| string` | `undefined` | The Style of the second pane | 2.38.2 | | resize-trigger-size | `number` | `3` | Size of the resize trigger. | 2.36.0 | | size | `string \| number` | `undefined` | Split is the controlled split size, when it's `number` it should in 0 ~ 1, when it's `string` it should be formatted in `${number}px`. | 2.38.0, `string` 2.38.2 | | watch-props | `Array<'defaultSize'>` | `undefined` | Default prop names that needed to be watched. Components will be updated after the prop is changed. Note: the `watch-props` itself is not reactive. | 2.38.0 | | on-drag-start | `(e: Event) => void` | `undefined` | Callback function when drag start. | 2.36.0 | | on-drag-move | `(e: Event) => void` | `undefined` | Callback function when dragging. | 2.36.0 | | on-drag-end | `(e: Event) => void` | `undefined` | Callback function when drag end. | 2.36.0 | | on-update:size | `(value: string \| number) => void` | `undefined` | Callback fired on `size` changes. If `props.value` or `props.defaultValue` is `string`, `value` is `string`. | 2.38.0, `string` 2.38.2 | ### Split Slots | Name | Parameters | Description | Version | | -------------- | ---------- | ------------------------ | ------- | | 1 | `()` | The first pane content. | 2.36.0 | | 2 | `()` | The Second pane content. | 2.36.0 | | resize-trigger | `()` | Split bar content. | 2.36.0 | --- # Collapse Transition A collapse item without any form of encapsulation. ## Demos ### Basic ```vue ``` ## API ### CollapseTransition Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | appear | `boolean` | `false` | Whether to play animation on first mounted. | | | display-directive | `'if' \| 'show'` | `'if'` | The directive to use for element rendering. `if` uses `v-if`, `show` uses `v-show`. | 2.45.0 | | show | `boolean` | `true` | Whether to show content. | | ### CollapseTransition Slots | Name | Parameters | Description | | ------- | ---------- | ---------------------------------- | | default | `()` | The content inside the transition. | --- # Discrete API(v2.29.0) If you want to use `useDialog`, `useMessage`, `useNotification`, `useLoadingBar`, `useModal` outside `setup`, you can use `createDiscreteApi` to create corresponding API. > **Caveat** > > 1. Discrete API won't be affected by `n-xxx-provider` in current app. If you need to share config, you should sync them manually. Also, you'd better not using discrete API and normal API together. 2. Do not call `createDiscreteApi` in `setup` since it may cause some unexpected behaviors. ## Demo ### Basic Use `createDiscreteApi` to create series of API. ```vue ``` ## API ### createDiscreteApi ```ts function createDiscreteApi( includes: Array<'message' | 'dialog' | 'notification' | 'loadingBar'>, options: { configProviderProps: Ref | ConfigProviderProps messageProviderProps: Ref | MessageProviderProps dialogProviderProps: Ref | DialogProviderProps notificationProviderProps: | Ref | NotificationProviderProps modalProviderProps: Ref | ModalProviderProps loadingBarProviderProps: | Ref | LoadingBarProviderProps } ): { // only API specified in `includes` will be created message: MessageApi dialog: DialogApi notification: NotificationApi loadingBar: LoadingBarApi modal: ModalApi // Vue app app: App unmount: () => void } {} ``` --- # Scrollbar It looks better but I'm sure it's not as reliable as native scrollbar. ## Demos ### Basic ```vue ``` ### Scroll horizontally ```vue ``` ### Trigger You can set different scrollbar trigger. Setting `trigger="none"` will make scrollbar always shown. Setting `trigger="hover"` will make scrollbar shown on mouse hover. ```vue ``` ### Mouse dragging cannot scroll to the bottom When the last element has a `margin-bottom`, dragging the scrollbar with the mouse cannot scroll to the bottom. This is caused by the native scrolling behavior of the browser. `n-scrollbar` cannot automatically handle this issue. You can solve this problem by setting `content-style` to `overflow: hidden;`. ```vue ``` ### Custom scrollbar style You can use `theme-overrides` to control the style of the scrollbar. ```vue ``` ### Theme You can use `n-config-provider`'s `theme-overrides` to customize every scrollbar theme variable. ```vue ``` ### Placement The placement of the scrollbar is controlled by `y-placement` and `x-placement`. ```vue ``` ## API ### Scrollbar Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | content-class | `string` | `undefined` | Class name of content div. | 2.38.2 | | content-style | `string \| object` | `undefined` | Style of content div. | 2.38.2 | | trigger | `'hover' \| 'none'` | `'hover'` | Trigger of show scrollbar. `'none'` means always show it. | 2.29.1 | | x-scrollable | `boolean` | `false` | Whether it can scroll horizontally. | | | x-placement | `'top' \| 'bottom'` | `bottom` | Scrollbar placement when scrolling horizontally. | 2.40.0 | | y-placement | `'left' \| 'right'` | `right` | Scrollbar placement when scrolling vertically. | 2.40.0 | | on-scroll | `(e: Event) => void` | `undefined` | Callback on scroll. | | ### Scrollbar Slots | Name | Parameters | Description | | ------- | ---------- | --------------- | | default | `()` | Scroll content. | ### Scrollbar Methods | Name | Type | Description | | --- | --- | --- | | scrollBy | `(options: { left?: number, top?: number, behavior?: ScrollBehavior }): void & (x: number, y: number) => void` | Scroll content by specific distance. | | scrollTo | `(options: { left?: number, top?: number, behavior?: ScrollBehavior }): void & (x: number, y: number) => void` | Scroll content. | --- # Virtual List When it comes to virtual lists, it can feel like a list is infinitely long, but in reality it is just secretly hiding the invisible elements. It's like a lazy programmer holding up a blank note and saying, "You can't see me, and I can't load myself!" Available since `2.36.0`. ## Demos ### Basic size ```vue ``` ### Dynamic size Set 'item-resizable' which can render items of unknown size. ```vue ``` ### Scroll ```vue ``` ### Keep state ```vue ``` ## API ### Virtual List Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | default-scroll-key | `string \| number` | `undefined` | Default scroll key. | 2.36.0 | | default-scroll-index | `number` | `undefined` | Default scroll index. | 2.36.0 | | ignore-item-resize | `boolean` | `false` | Ignore item resize. It can make runtime slightly faster, although it's hard to feel. | 2.36.0 | | items | `Array` | `[]` | Data to display. | 2.36.0 | | item-resizable | `boolean` | `false` | Whether dynamic sizing is enabled, you don't have to care about the size of the item, it will be calculated automatically. | 2.36.0 | | item-size | `number` | required | Displays the minimum height of the item in pixels to calculate scroll size and position. | 2.36.0 | | items-style | `string \| CSSProperties` | `undefined` | Items container style. | 2.36.0 | | key-field | `string` | `'key'` | Field name of option key. | 2.36.0 | | padding-top | `string \| number` | `undefined` | Distance from the top. | 2.36.0 | | padding-bottom | `string \| number` | `undefined` | Distance from the bottom. | 2.36.0 | | scrollbar-props | `ScrollbarProps` | `undefined` | Attribute reference [Scrollbar props](https://www.naiveui.com/en-US/components/scrollbar.md#Scrollbar-Props). | 2.36.0 | | visible-items-tag | `string` | `'div'` | Items container tag. | 2.36.0 | | visible-items-props | `object` | `undefined` | Items container prop. | 2.36.0 | | on-scroll | `(event: Event) => void` | `undefined` | Scrolling callback function. | 2.36.0 | | on-wheel | `(event: WheelEvent) => void` | `undefined` | Callback function for the wheel event. | 2.36.0 | | on-resize | `(event: ResizeObserverEntry) => void` | `undefined` | Element resizing callback function. | 2.36.0 | ### Virtual List Methods | Name | Type | Description | Version | | -------- | ---------- | --------------------- | ------- | | scrollTo | `ScrollTo` | Scroll to a position. | 2.36.0 | #### ScrollTo Type ```ts interface ScrollTo { (x: number, y: number): void (options: { left?: number top?: number behavior?: ScrollBehavior debounce?: boolean }): void (options: { index: number behavior?: ScrollBehavior debounce?: boolean }): void (options: { key: string | number behavior?: ScrollBehavior debounce?: boolean }): void (options: { position: 'top' | 'bottom' behavior?: ScrollBehavior debounce?: boolean }): void } ``` --- # Config Provider Config Provider is used to set global theme, set global language and set namespace for components (detached parts). For more info about theming, see [Customizing Theme](https://www.naiveui.com/en-US/docs/customize-theme.md). ## Demos ### Theme Set theme of inner components of `n-config-provider`. ```vue ``` ### Namespace (class on detached DOM) Some parts of component are detached to `document.body`. If you want to add a class to those detached elements, use `namespace` prop of `n-config-provider`. Open devtools to see detached part. ```vue ``` ### Inherit theme If you don't set theme of `n-config-provider`, the theme of `n-config-provider` is inherited by default. ```vue ``` ### Use OS theme Naive UI provides `useOsTheme` to get the current theme of your OS. ```vue ``` ### Locale ```vue ``` ### No wrapper DOM If you don't need wrapper DOM, set `abstract` on it. ```vue ``` ### Disable inline theme By default, naive-ui uses inline style to hold theme variables, so every component is bound with large amount of inline CSS. If you need SSR, or just make your devtools clear, you can enable `inline-theme-disabled` prop. Note that if you will change `theme-overrides` frequently, it's not recommended to enable the prop. Many outdated style elements will be keeped after `theme-overrides` changes. The prop is not responsive. ```vue ``` ### Component Size Configure component size with `component-options`. ```vue ``` ## API ### ConfigProvider Props | Name | Type | Default | Description | Version | | --- | --- | --- | --- | --- | | abstract | `boolean` | `false` | If `n-config-provider` has no wrapper DOM | | | breakpoints | `{ [k: string]: number }` | `{ xs: <640, s: ≥640, m: ≥1024, l: ≥1280, xl: ≥1536, xxl: ≥1920 }` | Responsive breakpoints, it will be used in `n-grid`. The prop is not responsive, you need to set it on its first mount. | | | cls-prefix | `string` | `undefined` | The class prefix of all inner components. (Since `2.40.0`) If you don't set the `cls-prefix` prop of `n-config-provider`, it will inherit the class prefix from its parent by default. Note that this prop is not reactive. | | | component-options | `GlobalComponentConfig` | `undefined` | Global component options. Some props can be configured per component. If set to `undefined` it will inherit its parent `n-config-provider`. | | | date-locale | `DateLocale \| null` | `undefined` | The date locale object to be consumed by its child. If set to `null` it will use the default `dateEnUS` locale. If set to `undefined` it will inherit its parent `n-config-provider`. | | | inline-theme-disabled | `boolean` | `false` | Whether to disabled inline theme CSS variables. If you won't change theme overrides frequently in client side, and need SSR or make devtools looks clear. You can enable the prop. Note that the prop is not responsive. | 2.26.0 | | katex | `object` | `undefined` | Katex object for `n-equation`. | 2.34.0 | | locale | `Locale \| null` | `undefined` | The locale object to be consumed by its child. If set to `null` it will use the default `enUS` locale. If set to `undefined` it will inherit its parent `n-config-provider`. | | | namespace | `string` | `undefined` | Class name of detached parts of components inside `n-config-provider` | | | preflight-style-disabled | `boolean` | `false` | Whether to disabled preflight style of naive-ui. If you disable it, you can take control of all global css. Also you can use `n-global-style` to apply global style (which is recommend since global style will be reactive). | 2.29.0 | | style-mount-target | `ParentNode` | `undefined` | Mounting target of style elements of components. Note that this prop is not reactive. | 2.40.0 | | tag | `string` | `'div'` | What tag `n-config-provider` will be rendered as | | | theme | `Theme \| null` | `undefined` | The theme object to be consumed by its child. If set to `null` it will use the default light theme. If set to `undefined` it will inherit its parent `n-config-provider`. For more details please see [Customizing Theme](https://www.naiveui.com/en-US/docs/customize-theme.md). | | | theme-overrides | `ThemeOverrides \| null` | `undefined` | The theme vars overrides to be consumed by its child. If set to `null` it will clear all theme vars. If set to `undefined` it will inherit its parent `n-config-provider`. For more details please see [Customizing Theme](https://www.naiveui.com/en-US/docs/customize-theme.md). | | #### GlobalComponentConfig Type ```ts interface GlobalComponentConfig { AutoComplete?: { size?: AutoCompleteSize } Button?: { size?: ButtonSize } Card?: { size?: CardSize } Cascader?: { size?: CascaderSize renderEmpty?: () => VNodeChild } Checkbox?: { size?: CheckboxSize } ColorPicker?: { size?: ColorPickerSize } DataTable?: { size?: DataTableSize renderFilter?: DataTableRenderFilter renderSorter?: DataTableRenderSorter renderEmpty?: () => VNodeChild } DatePicker?: { size?: DatePickerSize timePickerSize?: TimePickerSize } Descriptions?: { size?: DescriptionsSize } Dialog?: { iconPlacement?: IconPlacement } Dropdown?: { size?: DropdownSize } DynamicInput?: { buttonSize?: ButtonSize } DynamicTags?: { size?: DynamicTagsSize } Empty?: Pick Form?: { size?: FormSize } Input?: { size?: InputSize } InputNumber?: { size?: InputNumberSize } InputOtp?: { size?: InputOtpSize } Mention?: { size?: MentionSize } Pagination?: { size?: PaginationSize inputSize?: InputSize selectSize?: SelectSize } Popselect?: { size?: PopselectSize } Radio?: { size?: RadioSize } Rate?: { size?: RateSize } Result?: { size?: ResultSize } Select?: { size?: SelectSize renderEmpty?: () => VNodeChild } Skeleton?: { size?: SkeletonSize } Space?: { size?: SpaceSize } Switch?: { size?: SwitchSize } Table?: { size?: TableSize } Tabs?: { size?: TabsSize } Tag?: { size?: TagSize } TimePicker?: { size?: TimePickerSize } Transfer?: { size?: TransferSize renderEmpty?: () => VNodeChild } Tree?: { renderEmpty?: () => VNodeChild } TreeSelect?: { size?: TreeSelectSize renderEmpty?: () => VNodeChild } } ``` --- # Element Element has many theme variables provided by Naive UI. ## Demos ### Basic You can use CSS variables from it. If you need to use those variables in JS, please see [useThemeVars](https://www.naiveui.com/en-US/docs/theme.md#use-theme-vars). ```vue ``` ## API ### Element Props | Name | Type | Default | Description | | ---- | -------- | ------- | ------------------------------------------ | | tag | `string` | `'div'` | The tag `n-element` should be rendered as. | ### Element Slots | Name | Parameters | Description | | ------- | ---------- | --------------------------- | | default | `()` | The content of the element. | --- # Global Style For the following reasons, you may need to set some styles on `document.body` 1. Naive-ui will mount some global style that is unresponsive (to theme, not media query). For example `font-family`. The style works fine by default, however they won't change when theme is changed. 2. `n-config-provider` can't sync global style (for example, body's background color) outside it. You can use `n-global-style` to sync common global style to the body element. In the following example, `n-global-style` will sync the theme provided by `n-config-provider` to `document.body`. ## Usage ```html // follow config-provider's theme ... ``` --- # Legacy Transfer > **Warning** > > The transfer component is deprecated. It won't have any new feature and will be removed in the next major version. It's recommended to use new [Transfer](https://www.naiveui.com/en-US/components/transfer.md). Left, right, right, left... I'm a simple man, and I can play this all day. ## Demos ### Basic Basic example of the Transfer component. If you have tons of data, see below for virtualized list. ```vue ``` ### Large Data If you have tons of data, you may need to speed the transfer up! Set `virtual-scroll` on transfer to use a blazing fast transfer (which turns the ridiculous animation off). ```vue ``` ### Size Mixing sizes does not look harmonious. ```vue ``` ### Filterable ```vue ``` ## API ### Transfer Props | Name | Type | Default | Description | | --- | --- | --- | --- | | default-value | `Array \| null` | `null` | Default value. | | disabled | `boolean` | `true` | Disabled state. | | filterable | `boolean` | `false` | Filterable state. | | filter | `function` | `(pattern: string, option: TransferOption, from: 'source' \| 'target') => boolean` | A basic label string match function. | | options | `TransferOption[]` | `[]` | For configuration options, see the TransferOption Type below. | | size | `'small' \| 'medium' \| 'large'` | `'medium'` | Size. | | source-filter-placeholder | `string` | `undefined` | Placeholder for the source items search box. | | source-title | `string` | `'Source'` | Source items title. | | target-filter-placeholder | `string` | `undefined` | Placeholder for the target items search box. | | target-title | `string` | `'Target'` | Target items title. | | value | `Array \| null` | `undefined` | Value when being set manually. | | on-update:value | `(value: Array) => void` | `undefined` | Callback when the value changes. | | virtual-scroll | `boolean` | `false` | Enable virtual scrolling. | #### TransferOption Type | Property | Type | Description | | -------- | ------------------ | ------------------------------ | | label | `string` | The option's label to display. | | value | `string \| number` | The option's unique value. | | disabled | `boolean` | The option's disabled state. |