Navigation Menu

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

[Feature Request] $root.$emit('bv::toggle::modal', 'idOfModal') #2708

Closed
vesper8 opened this issue Feb 24, 2019 · 1 comment · Fixed by #2709
Closed

[Feature Request] $root.$emit('bv::toggle::modal', 'idOfModal') #2708

vesper8 opened this issue Feb 24, 2019 · 1 comment · Fixed by #2709

Comments

@vesper8
Copy link

vesper8 commented Feb 24, 2019

I am porting over from using https://github.com/euvl/vue-js-modal to using bootstrap-vue's modal and one thing I'm missing is that this other project had a means of programatically showing/hiding modals as well as a means of "toggling" modals

I need this because I use keyboard shortcuts to open modals and I want to be able to press the letter "A" and it will open a model if it's not opened, and if it is opened then it will close it.. effectively toggling it

Currently it seems you can only show or hide by using

this.$root.$emit('bv::show::modal', 'idOfModal')
and
this.$root.$emit('bv::hide::modal', 'idOfModal')

Since I created a single "modal" component which implements b-modal and I create all my modals by extending this component, I was easily able to add this functionality like this:

<template>
  <b-modal
    :id="id"
    v-model="shown"
    @shown="onShown"
    @hidden="onHidden"
  >
    <slot />
  </b-modal>
</template>

<script>
export default {
  props: {
    id: {
      type: String,
      default: () => '',
    },
  },

  data() {
    return {
      shown: false,
    };
  },

  mounted() {
    Bus.$on('toggle_modal', (modalId) => {
      if (this.id === modalId) {
        this.shown = !this.shown;
      }
    });
  },

  beforeDestroy() {
    Bus.$off('toggle_modal');
  },

  methods: {
    onShown() {
      this.$emit('opened');
    },

    onHidden() {
      this.$emit('closed');
    },
  },
};
</script>

but it would be nice if "toggle" was included in a future release

thanks!

@tmorehouse
Copy link
Member

I think this would be possible. We could add both a toggle() method and a toggle $root event.

The current way would be to use a v-model for show and toggle the value from true to false and vice versa (i.e. modalShow = !modalShow)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants