vue-multiselect icon indicating copy to clipboard operation
vue-multiselect copied to clipboard

Cannot read properties of null (reading 'blur') when changing view via select on Chrome

Open ztosyl opened this issue 1 year ago • 5 comments

Reproduction Link

  • N/A, I was unable to reproduce via a fiddle, not sure if that is set to 3.0? Here is a code snippet though that did reproduce:
<template>
  <div class="">
    <div v-if="something">
      <Multiselect
        ref="something"
        v-model="selectedOpt"
        :options="opts"
        :searchable="true"
        :group-select="false"
        :multiple="true"
        :close-on-select="false"
        @select="something = false"
      />
    </div>
    <div v-else>
      <Multiselect
        ref="somethingelse"
        v-model="selectedOpt"
        :options="opts"
        :searchable="true"
        :group-select="false"
        :multiple="true"
        :close-on-select="false"
        @select="something = true"
      />
    </div>
  </div>
</template>

<script>
import { Multiselect } from 'vue-multiselect'
import { ref } from 'vue'

export default {
  name: 'Repro',
  components: {
    Multiselect,
  },

  setup () {
    const selectedOpt = ref([])
    const something = ref(false)

    return { selectedOpt, something }
  },

  computed: {
    opts () {
      return ['switch']
    },
  },
}
</script>

Steps to reproduce

  • This is 3.0, on Vue 3. See above: have two multiselects that you can toggle between by choosing an option on one of them, an error will throw. This only happens on Chrome. If you trigger the select function that toggles between the selects, the error is thrown.

Expected behaviour

  • This works fine and throws no errors.

Actual behaviour

An error is thrown implying this.$refs.search is null, and errors on the following line:

if (typeof this.$refs.search !== 'undefined') this.$refs.search.blur();

The error is Cannot read properties of null (reading 'blur').

ztosyl avatar Mar 06 '23 18:03 ztosyl

Hi, also having the same error when unmouting the VueMultiselect component, it only occurs if the searchable prop is set to true.

The error is thrown by this condition check in multiselectMixin.js, related to PR https://github.com/shentao/vue-multiselect/pull/1497: https://github.com/shentao/vue-multiselect/blob/master/src/multiselectMixin.js#L691

if (this.searchable) {
  if (typeof this.$refs.search !== 'undefined') this.$refs.search.blur()
} else {
  if (typeof this.$el !== 'undefined') this.$el.blur()
}

gllmp avatar Mar 24 '23 01:03 gllmp

I get the same error

roelVerdonschot avatar Apr 20 '23 08:04 roelVerdonschot

same here

tomassabol avatar May 16 '23 20:05 tomassabol

Same error when using dynamic-options-provider. Happens If immediately leave the page while options are still being fetched.

10111282 avatar Jul 04 '23 12:07 10111282

Same error when search input is closed, i.e. searching for a tag and selecting the tag triggers the error.

nerminjukan avatar Oct 11 '23 14:10 nerminjukan