Skip to content

Commit

Permalink
Merge pull request #1386 from culturecreates/bugfix/issue-1320
Browse files Browse the repository at this point in the history
Bugfix/issue 1320
  • Loading branch information
AbhishekPAnil authored Oct 8, 2024
2 parents a8ecb7f + babf3d8 commit 1b03c16
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/assets/icons/Right.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/assets/icons/left.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 25 additions & 2 deletions src/components/MultilingualInput/MultilingualInput.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Tabs } from 'antd';
import { Button, Tabs } from 'antd';
import { WarningOutlined } from '@ant-design/icons';
import './multilingualInput.css';
import { useTranslation } from 'react-i18next';
Expand All @@ -9,6 +9,8 @@ import { capitalizeFirstLetter } from '../../utils/stringManipulations';
import { useOutletContext } from 'react-router-dom';
import useChildrenWithLanguageFallback from '../../hooks/useChildrenWithLanguageFallback';
import { isDataValid } from '../../utils/MultiLingualFormItemSupportFunctions';
import { ReactComponent as MoveLeftExtra } from '../../assets/icons/left.svg';
import { ReactComponent as MoveRightExtra } from '../../assets/icons/Right.svg';

/**
* MultilingualInput Component
Expand Down Expand Up @@ -42,6 +44,7 @@ function MultilingualInput({ children, ...rest }) {
} = rest;
const [currentCalendarData] = useOutletContext();
const { t } = useTranslation();
const [activeKey, setActiveKey] = React.useState(defaultTabProp);

const { fallbackStatus = {}, modifiedChildren = children } =
!skipChildModification &&
Expand Down Expand Up @@ -131,13 +134,33 @@ function MultilingualInput({ children, ...rest }) {
itemCollection.push(tabItem);
});

// Handle circular navigation for left and right clicks
const handleMoveLeft = () => {
const currentIndex = itemCollection.findIndex((item) => item.key === activeKey);
const newIndex = currentIndex > 0 ? currentIndex - 1 : itemCollection.length - 1;
setActiveKey(itemCollection[newIndex].key);
};

const handleMoveRight = () => {
const currentIndex = itemCollection.findIndex((item) => item.key === activeKey);
const newIndex = currentIndex < itemCollection.length - 1 ? currentIndex + 1 : 0;
setActiveKey(itemCollection[newIndex].key);
};

const extraNavigationIcons = {
left: <Button type="primary" onClick={handleMoveLeft} className="tabs-icon-extra" icon={<MoveLeftExtra />} />,
right: <Button type="primary" onClick={handleMoveRight} icon={<MoveRightExtra />} className="tabs-icon-extra" />,
};

return (
<Tabs
type="card"
defaultActiveKey={defaultTab}
activeKey={activeKey}
defaultTab={defaultTab}
items={itemCollection}
size="small"
tabBarGutter="0"
tabBarExtraContent={extraNavigationIcons}
tabPosition="top"
animated="false"
tabBarStyle={{ margin: '0' }}
Expand Down
36 changes: 36 additions & 0 deletions src/components/MultilingualInput/multilingualInput.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,42 @@
background: #ffffff;
}

.bilingual-input-tab .ant-tabs-nav-more {
display: none;
}

.bilingual-input-tab .ant-tabs-tab {
user-select: none;
-webkit-user-select: none; /* For Safari */
-moz-user-select: none; /* For Firefox */
}

.bilingual-input-tab .ant-tabs-nav .ant-tabs-nav-wrap.ant-tabs-nav-wrap-ping-right::after,
.bilingual-input-tab .ant-tabs-nav .ant-tabs-nav-wrap.ant-tabs-nav-wrap-ping-left::before {
opacity: 0;
}

.bilingual-input-tab .tabs-icon-extra:hover rect {
fill: #e6e6e6;
}

.bilingual-input-tab .tabs-icon-extra {
z-index: 1;
display: grid;
place-content: center;
border-radius: 4px;
padding: 0px;
border-color: #e6e6e6;
background: #ffffff;
width: 28px;
height: 28px;
}

.bilingual-input-tab .ant-tabs-extra-content {
display: grid;
place-content: center;
}

.ant-tabs > .ant-tabs-nav .ant-tabs-nav-list {
border-radius: 4px 4px 0px 0px;
}
Expand Down

0 comments on commit 1b03c16

Please sign in to comment.