opentiny / tiny-vue

TinyVue is an enterprise-class UI component library of OpenTiny community, support both Vue.js 2 and Vue.js 3, as well as PC and mobile.
https://opentiny.design/tiny-vue
MIT License
1.68k stars 266 forks source link

🐛 [Bug]: Collapse组件在阻止切换的时候,手动改变modelValue的值,阻止切换功能不生效 #1298

Open AcWrong02 opened 10 months ago

AcWrong02 commented 10 months ago

Version

latest

Vue Version

latest

Link to minimal reproduction

https://opentiny.design/vue-playground?mode=pc&theme=default#3.12|eyJzcmMvQXBwLnZ1ZSI6IjxzY3JpcHQgbGFuZz1cInRzeFwiPlxyXG4vLyDlvJXlhaUgQG9wZW50aW55L3Z1ZSDnu4Tku7ZcclxuaW1wb3J0IHsgQnV0dG9uLCBMaW5rIH0gZnJvbSAnQG9wZW50aW55L3Z1ZSdcclxuXHJcbmV4cG9ydCBkZWZhdWx0IHtcclxuICBjb21wb25lbnRzOiB7XHJcbiAgICBUaW55QnV0dG9uOiBCdXR0b24sXHJcbiAgICBUaW55TGluazogTGlua1xyXG4gIH0sXHJcbiAgZGF0YSgpIHtcclxuICAgIHJldHVybiB7XHJcbiAgICAgIG1zZzogJ2hlbGxvIHdvcmxkISdcclxuICAgIH1cclxuICB9XHJcbn1cclxuPC9zY3JpcHQ+XHJcblxyXG48dGVtcGxhdGU+XHJcbiAgPFRpbnlCdXR0b24+56Gu5a6aPC9UaW55QnV0dG9uPlxyXG4gIDxoMT57eyBtc2cgfX08L2gxPlxyXG4gIDxkaXYgY2xhc3M9XCJ0aW55dnVlXCI+XHJcbiAgICA8ZGl2IGNsYXNzPVwidGlueXZ1ZS1wYWdlXCI+XHJcbiAgICAgIHRpbnl2dWVcclxuICAgICAgPHRpbnktbGluayB0eXBlPVwic3VjY2Vzc1wiIGhyZWY9J2h0dHBzOi8vZ2l0aHViLmNvbS9vcGVudGlueS90aW55LXZ1ZSc+XHJcbiAgICAgICAgdGlueXZ1ZVxyXG4gICAgICA8L3RpbnktbGluaz5cclxuICAgIDwvZGl2PlxyXG4gIDwv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YXBzZS1pdGVtX19jb250ZW50ID4gKiB7XG4gICAgbGluZS1oZWlnaHQ6IDEuODtcbiAgfVxufVxuPC9zdHlsZT5cbiIsIl9vIjp7fX0=

Step to reproduce

点击click按钮,发现折叠面板仍然可以切换

What is expected

阻止切换功能应该要生效

What is actually happening

阻止切换功能不生效

Any additional comments (optional)

No response

Issues-translate-bot commented 10 months ago

Bot detected the issue body's language is not English, translate it automatically.


Title: 🐛 [Bug]: When the Collapse component prevents switching, the value of modelValue is manually changed, and the blocking switching function does not take effect.

AcWrong02 commented 10 months ago
<template>
  <tiny-collapse class="demo-collapse-wrap" v-model="activeName" accordion :before-close="beforeClose">
    <tiny-collapse-item title="一致性 Consistency" name="1">
      <div>与现实生活一致:与现实生活的流程、逻辑保持一致,遵循用户习惯的语言和概念;</div>
      <div>在界面中一致:所有的元素和结构需保持一致,比如:设计样式、图标和文本、元素的位置等。</div>
    </tiny-collapse-item>
    <tiny-collapse-item title="反馈 Feedback" name="2">
      <div>控制反馈:通过界面样式和交互动效让用户可以清晰的感知自己的操作;</div>
      <div>页面反馈:操作后,通过页面元素的变化清晰地展现当前状态。</div>
    </tiny-collapse-item>
    <tiny-collapse-item title="效率 Efficiency" name="3">
      <div>简化流程:设计简洁直观的操作流程;</div>
      <div>清晰明确:语言表达清晰且表意明确,让用户快速理解进而作出决策;</div>
      <div>帮助用户识别:界面简单直白,让用户快速识别而非回忆,减少用户记忆负担。</div>
    </tiny-collapse-item>
    <tiny-collapse-item title="可控 Controllability" name="4">
      <div>用户决策:根据场景可给予用户操作建议或安全提示,但不能代替用户进行决策;</div>
      <div>结果可控:用户可以自由的进行操作,包括撤销、回退和终止当前操作等。</div>
    </tiny-collapse-item>
  </tiny-collapse>
  <button @click="click">
    click
  </button>
</template>

<script setup>
import { ref } from 'vue'
import { Collapse as TinyCollapse, CollapseItem as TinyCollapseItem, Modal } from '@opentiny/vue'

const activeName = ref('1')

function beforeClose(item, activeNames) {
  Modal.message({ message: '阻止面板切换,当前点击面板:' + item.name, status: 'error' })
  return false
}

const click = ()=>{
  activeName.value = '3'
}
</script>

<style scoped lang="less">
.demo-collapse-wrap {
  .tiny-collapse-item__content > * {
    line-height: 1.8;
  }
}
</style>
wkif commented 10 months ago

尝试修复 1305

shenjunjian commented 3 months ago

虽然 wkif 提供修复了。 但我认为这个不应该算是问题, 不应该修改原来的逻辑。

阻止切换本来就是阻止从界面上产生操作, 并不是用来阻止脚本修改状态。 所在这个需要再讨论。

Issues-translate-bot commented 3 months ago

Bot detected the issue body's language is not English, translate it automatically.


Although wkif provides a fix. But I think this should not be considered a problem, and the original logic should not be modified.

Prevent switching is originally to prevent operations from the interface, and is not used to prevent scripts from modifying the state. This needs further discussion.