Skip to content

Commit 82ec30c

Browse files
Expandable list remove anchor (#5559)
Deprecate anchorElement on ExpandableList to avoid props drilling. The anchorElement should be the ExpandableList container itself
1 parent 7f7ea59 commit 82ec30c

File tree

10 files changed

+7
-26
lines changed

10 files changed

+7
-26
lines changed

packages/twenty-front/src/modules/activities/calendar/components/CalendarEventParticipantsResponseStatusField.tsx

+1-6
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,7 @@ export const CalendarEventParticipantsResponseStatusField = ({
104104
</StyledLabelAndIconContainer>
105105
<StyledDiv ref={participantsContainerRef}>
106106
{isRightDrawerAnimationCompleted && (
107-
<ExpandableList
108-
anchorElement={participantsContainerRef.current || undefined}
109-
isChipCountDisplayed
110-
>
111-
{styledChips}
112-
</ExpandableList>
107+
<ExpandableList isChipCountDisplayed>{styledChips}</ExpandableList>
113108
)}
114109
</StyledDiv>
115110
</StyledInlineCellBaseContainer>

packages/twenty-front/src/modules/activities/components/ActivityTargetChips.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { ExpandableList } from '@/ui/layout/expandable-list/components/Expandabl
66

77
type ActivityTargetChipsProps = {
88
activityTargetObjectRecords: ActivityTargetWithTargetRecord[];
9-
anchorElement?: HTMLElement;
109
maxWidth?: number;
1110
};
1211

@@ -19,12 +18,11 @@ const StyledContainer = styled.div<{ maxWidth?: number }>`
1918

2019
export const ActivityTargetChips = ({
2120
activityTargetObjectRecords,
22-
anchorElement,
2321
maxWidth,
2422
}: ActivityTargetChipsProps) => {
2523
return (
2624
<StyledContainer maxWidth={maxWidth}>
27-
<ExpandableList anchorElement={anchorElement} isChipCountDisplayed>
25+
<ExpandableList isChipCountDisplayed>
2826
{activityTargetObjectRecords.map(
2927
(activityTargetObjectRecord, index) => (
3028
<RecordChip

packages/twenty-front/src/modules/activities/inline-cell/components/ActivityTargetsInlineCell.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ export const ActivityTargetsInlineCell = ({
5353
/>
5454
}
5555
label="Relations"
56-
displayModeContent={({ cellElement }) => (
56+
displayModeContent={() => (
5757
<ActivityTargetChips
58-
anchorElement={cellElement}
5958
activityTargetObjectRecords={activityTargetObjectRecords}
6059
maxWidth={maxWidth}
6160
/>

packages/twenty-front/src/modules/object-record/record-field/components/FieldDisplay.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ export const FieldDisplay = ({
8080
) : isFieldLinks(fieldDefinition) ? (
8181
<LinksFieldDisplay
8282
isCellSoftFocused={isCellSoftFocused}
83-
cellElement={cellElement}
8483
fromTableCell={fromTableCell}
8584
/>
8685
) : isFieldCurrency(fieldDefinition) ? (

packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/LinksFieldDisplay.tsx

-3
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,18 @@ import { LinksDisplay } from '@/ui/field/display/components/LinksDisplay';
33

44
type LinksFieldDisplayProps = {
55
isCellSoftFocused?: boolean;
6-
cellElement?: HTMLElement;
76
fromTableCell?: boolean;
87
};
98

109
export const LinksFieldDisplay = ({
1110
isCellSoftFocused,
12-
cellElement,
1311
fromTableCell,
1412
}: LinksFieldDisplayProps) => {
1513
const { fieldValue } = useLinksField();
1614

1715
return (
1816
<LinksDisplay
1917
value={fieldValue}
20-
anchorElement={cellElement}
2118
isChipCountDisplayed={isCellSoftFocused}
2219
withExpandedListBorder={fromTableCell}
2320
/>

packages/twenty-front/src/modules/object-record/record-field/meta-types/display/components/MultiSelectFieldDisplay.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ type MultiSelectFieldDisplayProps = {
1111

1212
export const MultiSelectFieldDisplay = ({
1313
isCellSoftFocused,
14-
cellElement,
1514
fromTableCell,
1615
}: MultiSelectFieldDisplayProps) => {
1716
const { fieldValues, fieldDefinition } = useMultiSelectField();
@@ -26,7 +25,6 @@ export const MultiSelectFieldDisplay = ({
2625

2726
return (
2827
<ExpandableList
29-
anchorElement={cellElement}
3028
isChipCountDisplayed={isCellSoftFocused}
3129
withExpandedListBorder={fromTableCell}
3230
>

packages/twenty-front/src/modules/ui/field/display/components/LinksDisplay.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ import { getUrlHostName } from '~/utils/url/getUrlHostName';
1717

1818
type LinksDisplayProps = Pick<
1919
ExpandableListProps,
20-
'anchorElement' | 'isChipCountDisplayed' | 'withExpandedListBorder'
20+
'isChipCountDisplayed' | 'withExpandedListBorder'
2121
> & {
2222
value?: FieldLinksValue;
2323
};
2424

2525
export const LinksDisplay = ({
26-
anchorElement,
2726
isChipCountDisplayed,
2827
withExpandedListBorder,
2928
value,
@@ -55,7 +54,6 @@ export const LinksDisplay = ({
5554

5655
return (
5756
<ExpandableList
58-
anchorElement={anchorElement}
5957
isChipCountDisplayed={isChipCountDisplayed}
6058
withExpandedListBorder={withExpandedListBorder}
6159
>

packages/twenty-front/src/modules/ui/layout/expandable-list/components/ExpandableList.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ const StyledChipCount = styled(Chip)`
4141
`;
4242

4343
export type ExpandableListProps = {
44-
anchorElement?: HTMLElement;
4544
isChipCountDisplayed?: boolean;
4645
withExpandedListBorder?: boolean;
4746
};
@@ -53,7 +52,6 @@ export type ChildrenProperty = {
5352

5453
export const ExpandableList = ({
5554
children,
56-
anchorElement,
5755
isChipCountDisplayed: isChipCountDisplayedFromProps,
5856
withExpandedListBorder = false,
5957
}: {
@@ -75,10 +73,10 @@ export const ExpandableList = ({
7573
// @see https://floating-ui.com/docs/useFloating#elements
7674
const [childrenContainerElement, setChildrenContainerElement] =
7775
useState<HTMLDivElement | null>(null);
76+
7877
const [previousChildrenContainerWidth, setPreviousChildrenContainerWidth] =
7978
useState(childrenContainerElement?.clientWidth ?? 0);
8079

81-
// Used with useListenClickOutside.
8280
const containerRef = useRef<HTMLDivElement>(null);
8381

8482
const [firstHiddenChildIndex, setFirstHiddenChildIndex] = useState(
@@ -165,7 +163,7 @@ export const ExpandableList = ({
165163
)}
166164
{isListExpanded && (
167165
<ExpandedListDropdown
168-
anchorElement={anchorElement ?? childrenContainerElement ?? undefined}
166+
anchorElement={containerRef.current ?? undefined}
169167
onClickOutside={() => {
170168
resetFirstHiddenChildIndex();
171169
setIsListExpanded(false);

packages/twenty-front/src/modules/ui/layout/expandable-list/components/ExpandedListDropdown.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const ExpandedListDropdown = ({
4242
const { refs, floatingStyles } = useFloating({
4343
// @ts-expect-error placement accepts 'start' as value even if the typing does not permit it
4444
placement: 'start',
45-
middleware: [offset({ mainAxis: -1, crossAxis: -1 })],
45+
middleware: [offset({ mainAxis: -9, crossAxis: -7 })],
4646
elements: { reference: anchorElement },
4747
});
4848

packages/twenty-front/src/modules/ui/layout/expandable-list/components/__stories__/ExpandableList.stories.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const meta: Meta<typeof ExpandableList> = {
3535
},
3636
argTypes: {
3737
children: { control: false },
38-
anchorElement: { control: false },
3938
},
4039
};
4140

0 commit comments

Comments
 (0)