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(VItemGroup): use valueComparator when updating value #15395

Merged
merged 1 commit into from Jul 7, 2022

Conversation

hrobertson
Copy link
Contributor

Description

Fixes #15394

Motivation and Context

Using object values or a custom valueComparator, the model value was not updated correctly.

How Has This Been Tested?

unit tests and playground

Markup:

<template>
  <v-container>
    <v-card>
      <v-card-text>
        <p>This example uses object values. The model value is initialized with an object.</p>
        <p>The list item is correctly in the active state but when you click it to deselect it, a duplicate object is added to the model value.</p>
        <p>The active state is correct because it is determined by the toggleMethod() function which uses the valueComparator, and the default valueComparator is deepEqual.</p>
        <p>However, the updating of the model value is not correct because it does not use the valueComparator, it uses ===.</p>
        <p><strong>Multiple model value: {{ multipleModel }}</strong></p>
        <v-card max-width="500">
          <v-list>
            <v-list-item-group
              v-model="multipleModel"
              multiple
            >
              <v-list-item
                v-for="item in multipleItems"
                :key="item.text"
                :value="item"
              >
                <v-list-item-icon>
                  <v-icon>mdi-star</v-icon>
                </v-list-item-icon>
                <v-list-item-content>
                  <v-list-item-title>{{ item }}</v-list-item-title>
                </v-list-item-content>
              </v-list-item>
            </v-list-item-group>
          </v-list>
        </v-card>
      </v-card-text>
    </v-card>
    <v-card>
      <v-card-text>
        <p>This example does not use object values, but has a custom comparator that should make all values begining with the same letter act as one.</p>
        <p>The model value is initialized to 'bar'. Note that the 'bar' and 'baz' list items are active - as above, the active state correctly uses the valueComparator.</p>
        <p>Clicking either the 'bar' or 'baz' items should clear the model value but observe that, instead, clicking the 'baz' item changes the model value from 'bar' to 'baz'.</p>
        <p>This is because the updating of the model value does not use the valueComparator.</p>
        <p><strong>Single model value: {{ singleModel }}</strong></p>
        <v-card :max-width="500">
          <v-list>
            <v-list-item-group
              v-model="singleModel"
              :value-comparator="comparator"
            >
              <v-list-item
                v-for="(item, i) in singleItems"
                :key="i"
                :value="item"
              >
                <v-list-item-icon>
                  <v-icon>mdi-star</v-icon>
                </v-list-item-icon>
                <v-list-item-content>
                  <v-list-item-title>{{ item }}</v-list-item-title>
                </v-list-item-content>
              </v-list-item>
            </v-list-item-group>
          </v-list>
        </v-card>
      </v-card-text>
    </v-card>
  </v-container>
</template>

<script>
  export default {
    data: () => ({
      multipleModel: [
        {
          text: 'foo',
        },
      ],
      multipleItems: [
        {
          text: 'foo',
        },
        {
          text: 'bar',
        },
      ],
      singleModel: 'bar',
      singleItems: [
        'foo',
        'bar',
        'baz',
      ],
    }),
    methods: {
      comparator: (a, b) => a?.startsWith(b?.[0]),
    },
  }
</script>

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Improvement/refactoring (non-breaking change that doesn't add any features but makes things better)

Checklist:

  • The PR title is no longer than 64 characters.
  • The PR is submitted to the correct branch (master for bug fixes and documentation updates, dev for new features and backwards compatible changes and next for non-backwards compatible changes).
  • My code follows the code style of this project.
  • I've added relevant changes to the documentation (applies to new features and breaking changes in core library)

@KaelWD KaelWD merged commit 8bedb7c into vuetifyjs:master Jul 7, 2022
@hrobertson
Copy link
Contributor Author

Thanks @KaelWD. This was my first PR for vuetify.
I couldn't find any information on what prompts a release. When might 2.6.8 be released?

@KaelWD KaelWD added this to the v2.6.x milestone Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug Report][2.6.7] VItemGroup does not correctly use valueComparator
2 participants