PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0
Elementor Website Builder – more than just a page builder v4.3.0
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 4.1.0-beta2 4.1.0-dev2 4.0.8 All 454 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.3.0, at modules/atomic-widgets/elements/atomic-tabs/handlers/atomic-tabs-handler.js

93 lines 2.3 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, getDirectTabCount } from './utils';
4 import { getActiveTabId, setActiveTabIndex, validateActiveTab } from './editor-tabs-state';
5
6 const SELECTED_CLASS = 'e--selected';
7
8 register( {
9 elementType: 'e-tabs',
10 id: 'e-tabs-handler',
11 callback: ( { element, settings } ) => {
12 const tabsId = element.dataset.id;
13 const defaultActiveTab = settings[ 'default-active-tab' ];
14
15 Alpine.data( `eTabs${ tabsId }`, () => ( {
16 init() {
17 validateActiveTab( tabsId, getDirectTabCount( this.$el ) );
18 },
19 get activeTab() {
20 return getActiveTabId( tabsId, defaultActiveTab );
21 },
22
23 navigateTabs( { key, target: tab } ) {
24 const nextTab = getNextTab( key, tab );
25
26 nextTab.focus();
27 },
28 tab: {
29 ':id'() {
30 const index = getIndex( this.$el, TAB_ELEMENT_TYPE );
31
32 return getTabId( tabsId, index );
33 },
34 '@click'() {
35 setActiveTabIndex( tabsId, getIndex( this.$el, TAB_ELEMENT_TYPE ) );
36 },
37 '@keydown.arrow-right.prevent'( event ) {
38 this.navigateTabs( event );
39 },
40 '@keydown.arrow-left.prevent'( event ) {
41 this.navigateTabs( event );
42 },
43 ':class'() {
44 const id = this.$el.id;
45
46 return { [ SELECTED_CLASS ]: this.activeTab === id };
47 },
48 ':aria-selected'() {
49 const id = this.$el.id;
50
51 return this.activeTab === id ? 'true' : 'false';
52 },
53 ':tabindex'() {
54 const id = this.$el.id;
55
56 return this.activeTab === id ? '0' : '-1';
57 },
58 ':aria-controls'() {
59 const index = getIndex( this.$el, TAB_ELEMENT_TYPE );
60
61 return getTabContentId( tabsId, index );
62 },
63 },
64
65 tabContent: {
66 ':aria-labelledby'() {
67 const index = getIndex( this.$el, TAB_CONTENT_ELEMENT_TYPE );
68
69 return getTabId( tabsId, index );
70 },
71 'x-show'() {
72 const index = getIndex( this.$el, TAB_CONTENT_ELEMENT_TYPE );
73 const tabId = getTabId( tabsId, index );
74
75 const isActive = this.activeTab === tabId;
76
77 this.$nextTick( () => {
78 this.$el.classList.toggle( SELECTED_CLASS, isActive );
79 } );
80
81 return isActive;
82 },
83 ':id'() {
84 const index = getIndex( this.$el, TAB_CONTENT_ELEMENT_TYPE );
85
86 return getTabContentId( tabsId, index );
87 },
88 },
89 } ) );
90 },
91 } );
92
93