Vuetensils 0.4: awesome components and helpful directives
Tags: a11y, development, vue
Published: 2019-11-20 00:40:47

---
title: Vuetensils 0.4: awesome components and helpful directives
published: true
date: 2019-11-18 05:12:15 UTC
tags: Accessibility,Development,Vue.js,a11y
canonical_url: https://stegosource.com/vuetensils-0-4-awesome-components-helpful-directives/
---

The latest release of [Vuetensils](https://vuetensils.stegosource.com/) is out, and with it comes some exciting improvements including 2 brand new components ([VFile](https://vuetensils.stegosource.com/components/VFile.html), [VResize](https://vuetensils.stegosource.com/components/VResize.html)), and some handy directives ([autofocus](https://vuetensils.stegosource.com/directives/autofocus.html), [clickout](https://vuetensils.stegosource.com/directives/autofocus.html), [copy](https://vuetensils.stegosource.com/directives/copy.html)). These additions will make it faster and easier to create robust, accessible UIs with [Vue.js](https://vuejs.org/) with your own designs, and no bloat.

## VFile – custom, accessible file selection

First up is a look at the VFile component. By default, it looks and behaves like an HTML 5 [file input](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file), and that’s because under the hood it is one. However, it goes a step further by allowing developers to easily create custom drag and drop file selectors while maintaining accessible UIs.

Take for example the following:

<iframe title="Vuetensils VFile" sandbox="allow-scripts" security="restricted" width="1200" height="1000" src="https://codesandbox.io/embed/vuetensils-vfile-j8mek#?secret=KsPUJsbQph" data-secret="KsPUJsbQph"></iframe>

Users get a nice visible interface for dragging and dropping files or opening the file selection options, and any users relying on keyboards to navigate do not miss out on the experience.

Nice!

## VResize – container queries made easy

Not all [Vuetensils](https://vuetensils.stegosource.com/ "Vuetensils") components need to focus on accessibility. Some simply make it easier to develop complex UIs. With VResize, for example, we can customize our components based on their width and height.

Now, you might be thinking that [CSS media queries](https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries) solve the issue of providing different layouts at different sizes. However, the layout is not always based on **screen** size, but on the size of the element itself. This is where “[container queries](https://css-tricks.com/container-query-discussion/)” come into play.

Container queries are useful in the following scenario:

I have a component that should stack it’s contents when it’s less than 500px wide. If my screen is 900px wide and I only have this component, no problem. But if my layout is split in two, suddenly my screen is still 900px, but I only have 450px to work with, and my component ends up looking like butt. A smooshed butt at that.

Let’s take a look at that with a live example:

<iframe title="Vuetensils VResize" sandbox="allow-scripts" security="restricted" width="1200" height="1000" src="https://codesandbox.io/embed/vuetensils-vresize-j6lc3#?secret=OV3vwcqJ9f" data-secret="OV3vwcqJ9f"></iframe>

## Autofocus directive

There are some scenarios where you reveal a text input and you expect the next user behavior to interact with that input. The best experience for the user is for the text input to receive focus immediately. Think of when you go to Google, the search input is automatically focused, so you don’t have to click into it first.

With Vutensils’ [autofocus directive](https://vuetensils.stegosource.com/directives/autofocus.html) you can achieve the same thing within your Vue component like so:

```vue
<template>
  <label>
    Search for something
    <input type="search" v-autofocus />
  </label>
</template>
```

## Clickout directive

Another helpful directive, [Vuetensils](https://vuetensils.stegosource.com/ "Vuetensils")’ [clickout directive](https://vuetensils.stegosource.com/directives/clickout.html) let’s developers easily attach functionality to a click event that happens outside of a specific component:

```vue
<template>
  <div v-clickout="onClickout">Click outside and see.</div>
</template>

<script>
export default {
  methods: {
    onClickout() {
      alert('you clicked outside the div')
    }
  }
}
```

## Copy directive

Last but not least is the [copy directive](https://vuetensils.stegosource.com/directives/copy.html). Users are regularly presented with text that they need to copy and paste somewhere else. More and more often, we are seeing convenient click-to-copy functionality tied to these text elements because it makes for a good user experience.

With the copy directive, we can accomplish that feature very easily by simply doing the following:

```vue
<template>
  <button v-copy="`hello world`">Click to copy</button>
</template>
```