vuejs / vitepress

Vite & Vue powered static site generator.
https://vitepress.dev
MIT License
13.29k stars 2.15k forks source link

fix(theme): respect custom tag prop in VPButton component #4185

Closed rileychh closed 2 months ago

rileychh commented 2 months ago

Description

This PR fixes a bug in the VPButton component of the default VitePress theme. Previously, the tag prop was not being properly respected when determining the component to render. This change ensures that the tag prop takes precedence, falling back to a or button based on the presence of the href prop only if no custom tag is specified.

Here's a simple script that demonstrates the effect of this change:

const props = {
  tag: 'div',
  href: undefined,
}

// Before: Incorrectly evaluates to 'a'
const component = props.tag || props.href ? 'a' : 'button'

// After: Correctly evaluates to 'div'
const fixed = props.tag || (props.href ? 'a' : 'button')

In this example, even though we specify a custom tag 'div' and there's no href, the original code would incorrectly choose 'a'. The fixed version correctly respects the custom tag 'div'.

Linked Issues

None.

Additional Context

None.


[!TIP] The author of this PR can publish a preview release by commenting /publish below.