mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Add directives folder + focus directive
This commit is contained in:
11
src/directives/focus.test.ts
Normal file
11
src/directives/focus.test.ts
Normal 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
9
src/directives/focus.ts
Normal 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
2
src/directives/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
import './focus';
|
||||
import './tooltip';
|
||||
3
src/directives/readme.md
Normal file
3
src/directives/readme.md
Normal 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!'`
|
||||
1
src/directives/tooltip.ts
Normal file
1
src/directives/tooltip.ts
Normal file
@@ -0,0 +1 @@
|
||||
console.log('hi');
|
||||
Reference in New Issue
Block a user