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

Disabling select based on a boolean #20

Open
ishiki-arata opened this issue May 7, 2021 · 2 comments
Open

Disabling select based on a boolean #20

ishiki-arata opened this issue May 7, 2021 · 2 comments

Comments

@ishiki-arata
Copy link

I need to make the select disabled or enabled when I have activeEdit: true or false.

:disabled="!activeEdit"

I tried adding this to the but it does not work. Also tried readonly instead of disabled, doesn't work either. Any clue how to go around this?

Thank you!

@ishiki-arata
Copy link
Author

Help please :)

@desislavsd
Copy link
Owner

desislavsd commented May 29, 2021

Hey @ishiki-arata, truly sorry for the delayed response.

I thought this is covered but apparently there is an issue. The query input is disabled but the dropdown opens. I will definitely fix that but until then you can achieve the desired effect in a few ways:

  1. Apply pointer-events: none to prevent mouse interaction with the select. One will still be able to focus/open it using keyboard navigation with tab key though. Therefore option 2:

  2. During registration of the plugin you may override the open method to make it aware of the disabled attr:

import VueSelect, { vSelect } from '@desislavsd/vue-select'

Vue.use(VueSelect, {
    mixin: {
        methods: {
            // override the default `open` method
            open() {
                // prevent opening the dropdown if $attrs.disabled == true
                if (this.$attrs.disabled) return this.close();

                // otherwise call the original method we may take from the original 
                // vSelect component definition ( standard Vue component definition that has methods )
                return vSelect.methods.open.apply(this, arguments)
            },
        },
    },
})
  1. Is to customize the layout of the component but it will get too advanced ;)

For best results one may apply a combination of multiple strategies.

Sorry again, I really had some tough days! Wish you all the best!

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

No branches or pull requests

2 participants