Add directives folder + focus directive

This commit is contained in:
rijkvanzanten
2020-02-07 16:15:09 -05:00
parent 5553014091
commit caf641ca7b
5 changed files with 26 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
import { definition } from './focus';
describe('Directives / Focus', () => {
it('Calls focus() on the element on insertion', () => {
const el = { focus: jest.fn() };
// I don't care about the exact types of this Vue internal function. We just want to make
// sure `focus()` is being called on `el`.
definition.inserted!(el as any, null as any, null as any, null as any);
expect(el.focus).toHaveBeenCalled();
});
});

9
src/directives/focus.ts Normal file
View File

@@ -0,0 +1,9 @@
import Vue, { DirectiveOptions, DirectiveFunction } from 'vue';
export const definition: DirectiveOptions = {
inserted(el) {
el.focus();
}
};
Vue.directive('focus', definition);

2
src/directives/index.ts Normal file
View File

@@ -0,0 +1,2 @@
import './focus';
import './tooltip';

3
src/directives/readme.md Normal file
View File

@@ -0,0 +1,3 @@
# Directives
Directives are functions that are available on Vue components in templates. For example `v-focus` or `v-tooltip="'Hello world!'`

View File

@@ -0,0 +1 @@
console.log('hi');