Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Dropdown Overlapping Sidebar on Column Header Click in Horizontal Table When Scrolling #8287

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { ScrollWrapper } from '@/ui/utilities/scroll/components/ScrollWrapper';
import { useSaveCurrentViewFields } from '@/views/hooks/useSaveCurrentViewFields';
import { mapColumnDefinitionsToViewFields } from '@/views/utils/mapColumnDefinitionToViewField';

import { isScrollEnabledForRecordTableState } from '@/object-record/record-table/states/isScrollEnabledForRecordTableState';
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
import { RecordUpdateContext } from '../contexts/EntityUpdateMutationHookContext';
import { useRecordTable } from '../hooks/useRecordTable';

Expand Down Expand Up @@ -46,6 +48,11 @@ export const RecordTableWithWrappers = ({
recordTableId,
viewBarId,
}: RecordTableWithWrappersProps) => {
const isScrollEnabledForRecordTable = useRecoilComponentValueV2(
isScrollEnabledForRecordTableState,
recordTableId,
);

const { resetTableRowSelection, selectAllRows } = useRecordTable({
recordTableId,
});
Expand Down Expand Up @@ -80,7 +87,11 @@ export const RecordTableWithWrappers = ({

return (
<EntityDeleteContext.Provider value={deleteOneRecord}>
<ScrollWrapper contextProviderName="recordTableWithWrappers">
<ScrollWrapper
enableXScroll={isScrollEnabledForRecordTable.enableXScroll}
enableYScroll={isScrollEnabledForRecordTable.enableYScroll}
contextProviderName="recordTableWithWrappers"
>
<RecordUpdateContext.Provider value={updateRecordMutation}>
<StyledTableWithHeader>
<StyledTableContainer>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,48 @@
import styled from '@emotion/styled';

import { FieldMetadata } from '@/object-record/record-field/types/FieldMetadata';
import { isScrollEnabledForRecordTableState } from '@/object-record/record-table/states/isScrollEnabledForRecordTableState';
import { ColumnDefinition } from '@/object-record/record-table/types/ColumnDefinition';
import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';

import { RecordTableColumnHeadDropdownMenu } from './RecordTableColumnHeadDropdownMenu';

import { useSetRecoilComponentStateV2 } from '@/ui/utilities/state/component-state/hooks/useSetRecoilComponentStateV2';
import styled from '@emotion/styled';
import { useCallback } from 'react';
import { RecordTableColumnHead } from './RecordTableColumnHead';
import { RecordTableColumnHeadDropdownMenu } from './RecordTableColumnHeadDropdownMenu';

type RecordTableColumnHeadWithDropdownProps = {
column: ColumnDefinition<FieldMetadata>;
};

const StyledDropdown = styled(Dropdown)`
display: flex;

flex: 1;
z-index: ${({ theme }) => theme.lastLayerZIndex};
`;

export const RecordTableColumnHeadWithDropdown = ({
column,
}: RecordTableColumnHeadWithDropdownProps) => {
const setIsScrollEnabledForRecordTable = useSetRecoilComponentStateV2(
isScrollEnabledForRecordTableState,
);

const handleDropdownOpen = useCallback(() => {
setIsScrollEnabledForRecordTable({
lucasbordeau marked this conversation as resolved.
Show resolved Hide resolved
enableXScroll: false,
enableYScroll: false,
});
}, [setIsScrollEnabledForRecordTable]);

const handleDropdownClose = useCallback(() => {
setIsScrollEnabledForRecordTable({
enableXScroll: true,
enableYScroll: true,
});
}, [setIsScrollEnabledForRecordTable]);

return (
<StyledDropdown
onOpen={handleDropdownOpen}
onClose={handleDropdownClose}
dropdownId={column.fieldMetadataId + '-header'}
clickableComponent={<RecordTableColumnHead column={column} />}
dropdownComponents={<RecordTableColumnHeadDropdownMenu column={column} />}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { RecordTableComponentInstanceContext } from '@/object-record/record-table/states/context/RecordTableComponentInstanceContext';
import { createComponentStateV2 } from '@/ui/utilities/state/component-state/utils/createComponentStateV2';

export type ScrollEnabled = {
enableXScroll: boolean;
enableYScroll: boolean;
};

export const isScrollEnabledForRecordTableState =
createComponentStateV2<ScrollEnabled>({
key: 'isScrollEnabledForRecordTableState',
defaultValue: {
enableXScroll: true,
enableYScroll: true,
},
componentInstanceContext: RecordTableComponentInstanceContext,
});
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ export const Dropdown = ({
listenerId: dropdownId,
callback: () => {
onClickOutside?.();

if (isDropdownOpen) {
closeDropdown();
}
Expand All @@ -132,10 +131,12 @@ export const Dropdown = ({
useScopedHotkeys(
[Key.Escape],
() => {
closeDropdown();
if (isDropdownOpen) {
closeDropdown();
}
},
dropdownHotkeyScope.scope,
[closeDropdown],
[closeDropdown, isDropdownOpen],
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export const ScrollWrapper = ({
useScrollStates(contextProviderName);
const setScrollTop = useSetRecoilState(scrollTopComponentState);
const setScrollLeft = useSetRecoilState(scrollLeftComponentState);

const handleScroll = (overlayScroll: OverlayScrollbars) => {
const target = overlayScroll.elements().scrollOffsetElement;
setScrollTop(target.scrollTop);
Expand Down Expand Up @@ -78,7 +77,12 @@ export const ScrollWrapper = ({
}, [instance, setOverlayScrollbars]);

return (
<Context.Provider value={{ ref: scrollableRef, id: contextProviderName }}>
<Context.Provider
value={{
ref: scrollableRef,
id: contextProviderName,
}}
>
<StyledScrollWrapper ref={scrollableRef} className={className}>
{children}
</StyledScrollWrapper>
Expand Down
Loading