PluginProbe
Elementor Website Builder – more than just a page builder / 3.34.0-beta1
Elementor Website Builder – more than just a page builder v3.34.0-beta1
4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 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 All 457 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 3.34.0-beta1, at modules/atomic-widgets/elements/atomic-tabs/handlers/atomic-tabs-handler.js

94 lines 2.2 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 '@keydown.arrow-down.prevent'( event ) {
39 this.navigateTabs( event );
40 },
41 '@keydown.arrow-up.prevent'( event ) {
42 this.navigateTabs( event );
43 },
44 ':class'() {
45 const id = this.$el.id;
46
47 return this.activeTab === id ? SELECTED_CLASS : '';
48 },
49 ':aria-selected'() {
50 const id = this.$el.id;
51
52 return this.activeTab === id ? 'true' : 'false';
53 },
54 ':tabindex'() {
55 const id = this.$el.id;
56
57 return this.activeTab === id ? '0' : '-1';
58 },
59 ':aria-controls'() {
60 const index = getIndex( this.$el, TAB_ELEMENT_TYPE );
61
62 return getTabContentId( tabsId, index );
63 },
64 },
65
66 tabContent: {
67 ':aria-labelledby'() {
68 const index = getIndex( this.$el, TAB_CONTENT_ELEMENT_TYPE );
69
70 return getTabId( tabsId, index );
71 },
72 'x-show'() {
73 const index = getIndex( this.$el, TAB_CONTENT_ELEMENT_TYPE );
74 const tabId = getTabId( tabsId, index );
75
76 const isActive = this.activeTab === tabId;
77
78 this.$nextTick( () => {
79 this.$el.classList.toggle( SELECTED_CLASS, isActive );
80 } );
81
82 return isActive;
83 },
84 ':id'() {
85 const index = getIndex( this.$el, TAB_CONTENT_ELEMENT_TYPE );
86
87 return getTabContentId( tabsId, index );
88 },
89 },
90 } ) );
91 },
92 } );
93
94