[ Enhancement ] :: Tabs widget bug fixes (#2524)

* bugfix :: If we change the default tab field, the change is not immediately reflected on the widget
default tab field only accepts string value: make it reflect number values as well

* fixing exposed variable

* update

* cleanup

* pr changes updated : exposing current tab
This commit is contained in:
Kiran Ashok 2022-03-23 20:49:48 +05:30 committed by GitHub
parent 153ce5b60b
commit 01730b35e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 6 deletions

View file

@ -1,9 +1,18 @@
import React, { useRef, useState } from 'react';
import React, { useRef, useState, useEffect } from 'react';
import { SubCustomDragLayer } from '../SubCustomDragLayer';
import { SubContainer } from '../SubContainer';
import { resolveReferences, resolveWidgetFieldValue } from '@/_helpers/utils';
export const Tabs = function Tabs({ id, component, width, height, containerProps, currentState, removeComponent }) {
export const Tabs = function Tabs({
id,
component,
width,
height,
containerProps,
currentState,
removeComponent,
setExposedVariable,
}) {
const widgetVisibility = component.definition.styles?.visibility?.value ?? true;
const disabledState = component.definition.styles?.disabledState?.value ?? false;
const defaultTab = component.definition.properties.defaultTab.value;
@ -42,18 +51,26 @@ export const Tabs = function Tabs({ id, component, width, height, containerProps
};
const parentRef = useRef(null);
const [currentTab, setCurrentTab] = useState(parsedDefaultTab);
useEffect(() => {
setCurrentTab(parsedDefaultTab);
}, [parsedDefaultTab]);
useEffect(() => {
setExposedVariable('currentTab', currentTab);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentTab]);
return (
<div data-disabled={parsedDisabledState} className="jet-tabs card" style={computedStyles}>
<ul className="nav nav-tabs" data-bs-toggle="tabs">
{parsedTabs.map((tab) => (
<li className="nav-item" onClick={() => setCurrentTab(tab.id)} key={tab.id}>
<a
className={`nav-link ${currentTab === tab.id ? 'active' : ''}`}
className={`nav-link ${currentTab == tab.id ? 'active' : ''}`}
style={
currentTab === tab.id
currentTab == tab.id
? { color: parsedHighlightColor, borderBottom: `1px solid ${parsedHighlightColor}` }
: {}
}

View file

@ -1491,7 +1491,7 @@ export const componentTypes = [
visibility: { type: 'toggle', displayName: 'Visibility' },
disabledState: { type: 'toggle', displayName: 'Disable' },
},
exposedVariables: {},
exposedVariables: { currentTab: '' },
definition: {
others: {
showOnDesktop: { value: '{{true}}' },