PluginProbe
Elementor Website Builder – more than just a page builder / 4.0.2
Elementor Website Builder – more than just a page builder v4.0.2
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
elementor / modules / atomic-widgets / elements / atomic-tabs / handlers / atomic-tabs-handler.js

atomic-tabs-handler.js in Elementor Website Builder – more than just a page builder 4.0.2, at modules/atomic-widgets/elements/atomic-tabs/handlers/atomic-tabs-handler.js

88 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { register } from '@elementor/frontend-handlers';
2 import { Alpine } from '@elementor/alpinejs';
3 import { TAB_ELEMENT_TYPE, TAB_CONTENT_ELEMENT_TYPE, getTabId, getTabContentId, getIndex, getNextTab } from './utils';
4
5 const SELECTED_CLASS = 'e--selected';
6
7 register( {
8 elementType: 'e-tabs',
9 id: 'e-tabs-handler',
10 callback: ( { element, settings } ) => {
11 const tabsId = element.dataset.id;
12
13 Alpine.data( `eTabs${ tabsId }`, () => ( {
14 activeTab: settings[ 'default-active-tab' ],
15
16 navigateTabs( { key, target: tab } ) {
17 const nextTab = getNextTab( key, tab );
18
19 nextTab.focus();
20 },
21 tab: {
22 ':id'() {
23 const index = getIndex( this.$el, TAB_ELEMENT_TYPE );
24
25 return getTabId( tabsId, index );
26 },
27 '@click'() {
28 const id = this.$el.id;
29
30 this.activeTab = id;
31 },
32 '@keydown.arrow-right.prevent'( event ) {
33 this.navigateTabs( event );
34 },
35 '@keydown.arrow-left.prevent'( event ) {
36 this.navigateTabs( event );
37 },
38 ':class'() {
39 const id = this.$el.id;
40
41 return { [ SELECTED_CLASS ]: this.activeTab === id };
42 },
43 ':aria-selected'() {
44 const id = this.$el.id;
45
46 return this.activeTab === id ? 'true' : 'false';
47 },
48 ':tabindex'() {
49 const id = this.$el.id;
50
51 return this.activeTab === id ? '0' : '-1';
52 },
53 ':aria-controls'() {
54 const index = getIndex( this.$el, TAB_ELEMENT_TYPE );
55
56 return getTabContentId( tabsId, index );
57 },
58 },
59
60 tabContent: {
61 ':aria-labelledby'() {
62 const index = getIndex( this.$el, TAB_CONTENT_ELEMENT_TYPE );
63
64 return getTabId( tabsId, index );
65 },
66 'x-show'() {
67 const index = getIndex( this.$el, TAB_CONTENT_ELEMENT_TYPE );
68 const tabId = getTabId( tabsId, index );
69
70 const isActive = this.activeTab === tabId;
71
72 this.$nextTick( () => {
73 this.$el.classList.toggle( SELECTED_CLASS, isActive );
74 } );
75
76 return isActive;
77 },
78 ':id'() {
79 const index = getIndex( this.$el, TAB_CONTENT_ELEMENT_TYPE );
80
81 return getTabContentId( tabsId, index );
82 },
83 },
84 } ) );
85 },
86 } );
87
88