tusen-ai / naive-ui

A Vue 3 Component Library. Fairly Complete. Theme Customizable. Uses TypeScript. Fast.

Home Page:https://www.naiveui.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

switch icon can not update when theme is Dark

smilingovo opened this issue · comments

Describe the bug

When I use the vueuse tool library to perform a theme's localstorage response, the icon does not update properly when the theme is dark by default

Steps to reproduce

<n-switch v-model:value="isDark" @update:value="toggleTheme" size="medium"> <template #icon> <n-icon> <i class="bi" :class="isDark ? 'bi-sun-fill' : 'bi-moon-fill'"></i> </n-icon> </template> </n-switch>

Link to minimal reproduction

none

System Info

"system":"windows10"
"naive-ui": "^2.38.1"
"@vueuse/core": "^10.9.0"

Used Package Manager

pnpm

Validations

Have you tried:

<n-icon> <i class="bi" :class="{ 'bi-sun-fill': isDark, 'bi-moon-fill': !isDark }"></i> </n-icon>

That is assuming isDark is a Boolean. If isDark is a string, then you will need more logic. For instance if isDark = 'Yes', then you will need to implement that isDark === 'Yes' or isDark !== 'Yes'

Also, the Switch API offers a default-value prop. Which by default is set to false. I'd take a look at that as well.

As well as the example integration for customizing icons:

<n-switch v-model:value="active" size="large">
    <template #checked-icon>
      <n-icon :component="ArrowForwardOutline" />
    </template>
    <template #unchecked-icon>
      <n-icon :component="ArrowBackOutline" />
    </template>
</n-switch>