Files
element-plus/docs/en-US/guide/custom-defaults.md
rzzf de984256ab feat(utils): add setPropsDefaults method (#23612)
* feat(components): add `setPropsDefaults` method

* chore: cleanup

* test: add test

* docs: add Custom Defaults

* fix: apply coderabbit suggest

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* feat: support array props

* chore: fix type error

* refactor: use fromPairs replace zipObject

* fix: correct type

* refactor: apply coderabbit suggest

* docs: detail tip

* docs: add warning

* Update docs/en-US/guide/custom-defaults.md

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* chore: revert main.ts

* docs: update

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
2026-02-14 13:37:05 +01:00

1.4 KiB
Raw Permalink Blame History

title, lang
title lang
Custom Defaults en-US

Custom Defaults

The component library allows you to customize the default values of component props.

By configuring defaults in advance, you can reduce repetitive prop declarations and keep your templates cleaner and more consistent.

Basic Usage

You can customize a components default props using the static setPropsDefaults method provided by the component.

:::tip

Note that default customization only applies to declarative components and must be performed before the component is initialized.

The configured defaults are global. Once set, they will apply to all Vue applications where the component is registered.

Once the component is rendered for the first time, the defaults become immutable and can no longer be changed.

:::

import { ElButton } from 'element-plus'

ElButton.setPropsDefaults({
  type: 'primary',
  size: 'small',
})

After applying the customization, the following two usages are equivalent:

<template>
  <el-button>Hello</el-button>
  <el-button type="primary" size="small">Hello</el-button>
</template>

::: warning

It is not recommended to set default values for components that are internally used by other components.

For example:

// This will cause the behavior of the el-autocomplete component to change.
ElInput.setPropsDefaults({ maxlength: 1 })

:::