element-plus [Component] [popover] popover can't be opened when use v-model:visible and trigger:click

c2e8gylq  于 4个月前  发布在  其他
关注(0)|答案(7)|浏览(40)

Bug Type: Component

Environment

  • Vue Version: 3.2.47
  • Element Plus Version: 2.2.34
  • Browser / OS: Chrome 110.0.5481.178
  • Build Tool: Vite

Reproduction

  • el-popover

Element Plus Playground

Steps to reproduce

<script setup>
const visible = ref(false)
</script>

<template>
  <template>
  <div>
    <el-popover
      v-model:visible="visible"
      placement="top-start"
      :width="200"
      trigger="click"
      content="content1"
    >
      <template #reference>
        <el-button @click="visible = true">button1</el-button>
      </template>
    </el-popover>

    <p>
      The popover will be hidden immediately when click button1(use v-model:visible )
    </p>
  </div>
</template>

</template>

What is Expected?

popver stay open when click

What is actually happening?

popver is hidden immediately after opening

Additional comments

:visible works, but v-model:visible doesn't

(empty)

y1aodyip

y1aodyip1#

@co2color when using v-model:visible , the control is all on your side, the trigger won't be able to update the state, update them yourself.

mpgws1up

mpgws1up2#

@co2color when using v-model:visible , the control is all on your side, the trigger won't be able to update the state, update them yourself.

Sorry, can you give me a playground demo?I think I'm updating the state myself....( use @click="visible = true" ) ,but popever is be hideen because visible will be false immediately

v1l68za4

v1l68za43#

<el-popover
      :visible="visible1"
      placement="top-start"
      :width="200"
      content="content1"
    >
      <template #reference>
        <el-button @click="visible1 = true">button1</el-button>
      </template>
    </el-popover>
q35jwt9p

q35jwt9p4#

<el-popover
      :visible="visible1"
      placement="top-start"
      :width="200"
      content="content1"
    >
      <template #reference>
        <el-button @click="visible1 = true">button1</el-button>
      </template>
    </el-popover>

But I mean that use v-model:visible="visible" confuse me

f45qwnt8

f45qwnt85#

controlled
You need to understand what is bidirectional and what is unidirectional. You use v-model, and you modify visible in the internal button, which causes you to modify it to true, and the control internally to false.

kcugc4gi

kcugc4gi6#

Humm, I think this confuses me as well 😢 , and I think @co2color was right, when using :visible="visible" the visibility should never be updated by the down stream component, and when using v-model:visible="visible" it should be able to be controlled by both ends, and I think this is a bug so I reopened this issue and I will assign it to myself.

ttygqcqt

ttygqcqt7#

It is two-way, so his button is triggered to change to true first, and at this time popper's clickoutside is also triggered, and it changes back to false.

相关问题