Skip to content

Dynamically add or remove Tab component,may cause compoment's selected status abnormally  #1493

@mahiru-forever

Description

@mahiru-forever

Whatever i use the selected(Tabs component's props) or not, it always operation abnormally.I saw the code, Tabs Component's tabs variable seem only perceive the newly added Tab component, but when delete, tabs is no change. I'm not sure it's my code wrong or not used correctly.
Look forward to your answer.

// tabs component template
<Tabs>
  {#each tabs as { label, key }}
  <Tab>
     {label}
       <span class="del-tab" on:click|preventDefault|stopPropagation={() => delMehod(key)}>x</span>
  </Tab>
  {/each}
  <div class="tab-add" on:click={addMethod}>+</div>
</Tabs>

// dynamically remove
function delMehod(key) {
  tabs = tabs.filter(v => {
    return v.key !== el.detail
  })
}

// dynamically add
function addMethod() {
  tabs = [...tabs, { label:'xxx', key: 'xxx' }]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions