Warning: session_start(): open(/var/lib/php/fpm/session/sess_7efngr06p7b0e8pg2v3dk5t0kh, O_RDWR) failed: Permission denied (13) in /var/www/tst02/wp-content/plugins/wordpress-social-login/wp-social-login.php on line 64

Warning: session_start(): Failed to read session data: files (path: /var/lib/php/fpm/session) in /var/www/tst02/wp-content/plugins/wordpress-social-login/wp-social-login.php on line 64

Notice: Undefined index: HTTP_REFERER in /var/www/tst02/wp-content/themes/mdbootstrap4/inc/cookie-setter.php on line 8
Vue Hotkey Directive - Bootstrap 4 & Material Design - Material Design for Bootstrap

Vue Bootstrap Hotkey MDB Pro component

Vue Hotkey - Bootstrap 4 & Material Design

The mdb-hotkey is a custom directive which allows to set callbacks for key combinations.

Live Preview

Basic usage

Step 1: Import the directive from 'mdbvue'


        <script>
          import { mdbHotkey } from "mdbvue";
        </script>
      

Step 2: Add mdbHotkey to the directives object


        <script>
          import { mdbHotkey } from "mdbvue";
          export default {
            directives: {
              mdbHotkey
            }
          };
        </script>
      

Step 3: Attach the directive to the element on which you wish to listen for events and pass a keymap as the value.


        <template>
          <div>
            <p>
              Press alt+l to insert a default text / ctrl + c to clear textarea
            </p>
            <mdb-input
              type="textarea"
              v-model="value"
              v-mdb-hotkey="inputKeymap"
              :rows="3"
              label="Press a key combination"
            />
          </div>
        </template>
      

        <script>
          import { mdbHotkey, mdbInput } from "mdbvue";
          export default {
            components: { mdbInput },
            data() {
              return {
                value: ""
              };
            },
            computed: {
              inputKeymap() {
                return {
                  "alt+l": this.insertText,
                  "ctrl+c": this.removeText
                };
              }
            },
            methods: {
              insertText() {
                this.value =
                  "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.";
              },
              removeText() {
                this.value = "";
              }
            },
            directives: {
              mdbHotkey
            }
          };
        </script>
      

Options

Name Description Example
:window Adds the event listener to the window instead of the element <div v-mdb-hotkey:window="keymap" ></div>
:document Adds the event listener to the document instead of the element <div v-mdb-hotkey:document="keymap" ></div>

Modifiers

Name Description Example
.stop Calls stopPropagation method on the keydown event <div v-mdb-hotkey.stop="keymap" ></div>
.prevent Calls preventDefault method on the keydown event <div v-mdb-hotkey.prevent="keymap" ></div>

Tabs example

Live Preview

        <template>
          <div v-mdb-hotkey:window.prevent="documentKeymap">
            <p>Use right/left arrows to switch tabs</p>
            <mdb-tabs
              :active="activeTab"
              @activeTab="activeTab = $event"
              tabs
              card
              class="mb-5"
              color="indigo"
              justify
              :links="[
                { text: 'Home' },
                { text: 'Profile' },
                { text: 'Contact' }
              ]"
              :content="tabs"
            />
          </div>
        </template>
      

        <script>
          import { mdbTabs, mdbHotkey } from "mdbvue";

          export default {
            components: {
              mdbTabs
            },
            data() {
              return {
                activeTab: 0,
                tabs: [
                  `Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.`,
                  `Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.`,
                  `Etsy mixtape wayfarers, ethical wes anderson tofu before they sold out mcsweeney's organic lomo retro fanny pack lo-fi farm-to-table readymade. Messenger bag gentrify pitchfork tattooed craft beer, iphone skateboard locavore carles etsy salvia banksy hoodie helvetica. DIY synth PBR banksy irony. Leggings gentrify squid 8-bit cred pitchfork. Williamsburg banh mi whatever gluten-free, carles pitchfork biodiesel fixie etsy retro mlkshk vice blog. Scenester cred you probably haven't heard of them, vinyl craft beer blog stumptown. Pitchfork sustainable tofu synth chambray yr.`
                ]
              };
            },
            computed: {
              documentKeymap() {
                return {
                  ArrowRight: this.changeTab,
                  ArrowLeft: () => this.changeTab(-1)
                };
              }
            },
            methods: {
              changeTab(direction = 1) {
                let next = this.activeTab + direction;
                if (next < 0) next = this.tabs.length - 1;
                else if (next > this.tabs.length - 1) next = 0;

                this.activeTab = next;
              }
            },
            directives: { mdbHotkey }
          };
        </script>