Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(group): update the value when delete an item #19663

Merged
merged 2 commits into from
Apr 22, 2024

Conversation

lzl0304
Copy link
Contributor

@lzl0304 lzl0304 commented Apr 22, 2024

Description

fixes #19655
fixes #19213

Markup:

<script setup>
  import { ref } from 'vue'

  const createItem = (title, hasValue = false) => ({
    id: Math.floor(Math.random() * 1000),
    title,
    content: '',
    value: hasValue ? Math.random().toString(16).slice(2) : undefined,
  })

  const items = ref([createItem('A'), createItem('B'), createItem('C')])

  const onAddItem = () => {
    items.value.push(createItem('D'))
  }

  const onDelete = (event, itemToBeDeleted) => {
    event.stopPropagation()
    const index = items.value.findIndex(item => item.id === itemToBeDeleted.id)
    items.value.splice(index, 1)
  }
</script>

<template>
  <v-app>
    <v-container>
      <v-expansion-panels class="accordion">
        <v-expansion-panel v-for="item in items" :key="item.id" :value="item.value">
          <v-expansion-panel-title>
            <template #actions="{ expanded }">
              <span class="">{{ `key: ${item.id}` }}</span>
              <v-icon
                :icon="expanded ? 'mdi-chevron-up' : 'mdi-chevron-down'"
                class="action"
              />
              <v-icon
                class="action delete"
                icon="mdi-delete"
                @click="event => onDelete(event, item)"
              />
            </template>
            <template #default="{ expanded }">
              <v-row no-gutters>
                <v-col class="d-flex justify-start" cols="11">
                  <v-text-field
                    v-model="item.title"
                    placeholder="Title"
                    variant="solo-filled"
                    hide-details
                  />
                </v-col>
              </v-row>
            </template>
          </v-expansion-panel-title>
          <v-expansion-panel-text>
            <v-row no-gutters>
              <v-col class="d-flex justify-start" cols="12">
                <v-textarea v-model="item.content" />
              </v-col>
            </v-row>
          </v-expansion-panel-text>
        </v-expansion-panel>
      </v-expansion-panels>
      <v-btn class="add-item-button" @click="onAddItem">
        <v-icon>mdi-plus</v-icon>
        Add item
      </v-btn>
    </v-container>
  </v-app>
</template>

<style>
.add-item-button {
  margin-top: 25px;
}
</style>

@johnleider johnleider added T: bug Functionality that does not work as intended/expected E: group Group composable labels Apr 22, 2024
@johnleider johnleider added this to the v3.5.x milestone Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E: group Group composable T: bug Functionality that does not work as intended/expected
Projects
None yet
2 participants