Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2715 from teamleadercrm/tab-group-scrolling-fix
Browse files Browse the repository at this point in the history
[FIX] - Use Ref instead of a constant
  • Loading branch information
eniskraasniqi1 committed Jul 14, 2023
2 parents 74d88f8 + 4493eaf commit aef0530
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

### Dependency updates

## [22.2.1] - 2023-07-13

### Fixed

`TabGroup`: Use ref.current instead of constant. ([@eniskraasniqi1](https://https://github.com/eniskraasniqi1) in [#2715](https://github.com/teamleadercrm/ui/pull/2715))

## [22.2.0] - 2023-07-11

### Added
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@teamleader/ui",
"description": "Teamleader UI library",
"version": "22.2.0",
"version": "22.2.1",
"author": "Teamleader <development@teamleader.eu>",
"bugs": {
"url": "https://github.com/teamleadercrm/ui/issues"
Expand Down
15 changes: 7 additions & 8 deletions src/components/tab/TabGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ const TabGroup: GenericComponent<TabGroupProps> = ({ children, className, size,
const [canScrollLeft, setCanScrollLeft] = useState(false);
const [canScrollRight, setCanScrollRight] = useState(false);

const scrollContainerElement = scrollContainerRef.current;

const checkForScrollPosition = () => {
if (scrollContainerElement) {
const { scrollLeft, scrollWidth, clientWidth } = scrollContainerElement;
if (scrollContainerRef.current) {
const { scrollLeft, scrollWidth, clientWidth } = scrollContainerRef.current;

setCanScrollLeft(scrollLeft > 0);
setCanScrollRight(scrollLeft < scrollWidth - clientWidth);
Expand All @@ -39,7 +37,7 @@ const TabGroup: GenericComponent<TabGroupProps> = ({ children, className, size,
const scrollToActiveTab = () => {
if (activeTabRef.current) {
const { offsetLeft } = activeTabRef.current;
scrollContainerElement?.scrollTo({ left: offsetLeft - SCROLL_BUTTON_WIDTH });
scrollContainerRef.current?.scrollTo({ left: offsetLeft - SCROLL_BUTTON_WIDTH });
}
};
const handleResize = () => {
Expand All @@ -52,13 +50,14 @@ const TabGroup: GenericComponent<TabGroupProps> = ({ children, className, size,
};

const scrollContainerBy = (distance: number) => {
scrollContainerElement?.scrollBy({ left: distance, behavior: 'smooth' });
scrollContainerRef.current?.scrollBy({ left: distance, behavior: 'smooth' });
};

useEffect(() => {
smoothScroll.polyfill();
scrollContainerElement?.addEventListener('scroll', handleScroll);
return () => scrollContainerElement?.removeEventListener('scroll', handleScroll);
scrollContainerRef.current?.addEventListener('scroll', handleScroll);
// eslint-disable-next-line react-hooks/exhaustive-deps
return () => scrollContainerRef.current?.removeEventListener('scroll', handleScroll);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down
10 changes: 5 additions & 5 deletions src/components/wysiwygEditor/WysiwygEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ const WysiwygEditor: GenericComponent<WysiwygEditorProps> = ({
const [isFocused, setIsFocused] = useState(false);
const [isPlaceholderShown, setIsPlaceholderShown] = useState(true);
const editorRef = useRef<EditorType>(null);
const editorElement = editorRef.current;

useEffect(() => {
if (autoFocus) {
Expand All @@ -116,19 +115,20 @@ const WysiwygEditor: GenericComponent<WysiwygEditorProps> = ({
}, [autoFocus]);

useEffect(() => {
if (!onKeyDown || !editorElement?.wrapper) {
if (!onKeyDown || !editorRef.current?.wrapper) {
return;
}

const handleKeyDown = (event: React.KeyboardEvent) => onKeyDown(event);

editorElement.wrapper.addEventListener('keydown', handleKeyDown);
editorRef.current.wrapper.addEventListener('keydown', handleKeyDown);

return () => {
if (!onKeyDown || !editorElement?.wrapper) {
if (!onKeyDown || !editorRef.current?.wrapper) {
return;
}
editorElement.wrapper.removeEventListener('keydown', handleKeyDown);
// eslint-disable-next-line react-hooks/exhaustive-deps
editorRef.current.wrapper.removeEventListener('keydown', handleKeyDown);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down

0 comments on commit aef0530

Please sign in to comment.