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

Expandable list remove anchor #5559

Merged
merged 4 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -104,12 +104,7 @@ export const CalendarEventParticipantsResponseStatusField = ({
</StyledLabelAndIconContainer>
<StyledDiv ref={participantsContainerRef}>
{isRightDrawerAnimationCompleted && (
<ExpandableList
anchorElement={participantsContainerRef.current || undefined}
isChipCountDisplayed
>
{styledChips}
</ExpandableList>
<ExpandableList isChipCountDisplayed>{styledChips}</ExpandableList>
)}
</StyledDiv>
</StyledInlineCellBaseContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { ExpandableList } from '@/ui/layout/expandable-list/components/Expandabl

type ActivityTargetChipsProps = {
activityTargetObjectRecords: ActivityTargetWithTargetRecord[];
anchorElement?: HTMLElement;
maxWidth?: number;
};

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

export const ActivityTargetChips = ({
activityTargetObjectRecords,
anchorElement,
maxWidth,
}: ActivityTargetChipsProps) => {
return (
<StyledContainer maxWidth={maxWidth}>
<ExpandableList anchorElement={anchorElement} isChipCountDisplayed>
<ExpandableList isChipCountDisplayed>
{activityTargetObjectRecords.map(
(activityTargetObjectRecord, index) => (
<RecordChip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export const ActivityTargetsInlineCell = ({
label="Relations"
displayModeContent={({ cellElement }) => (
<ActivityTargetChips
anchorElement={cellElement}
activityTargetObjectRecords={activityTargetObjectRecords}
maxWidth={maxWidth}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export const FieldDisplay = ({
) : isFieldLinks(fieldDefinition) ? (
<LinksFieldDisplay
isCellSoftFocused={isCellSoftFocused}
cellElement={cellElement}
fromTableCell={fromTableCell}
/>
) : isFieldCurrency(fieldDefinition) ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,18 @@ import { LinksDisplay } from '@/ui/field/display/components/LinksDisplay';

type LinksFieldDisplayProps = {
isCellSoftFocused?: boolean;
cellElement?: HTMLElement;
fromTableCell?: boolean;
};

export const LinksFieldDisplay = ({
isCellSoftFocused,
cellElement,
fromTableCell,
}: LinksFieldDisplayProps) => {
const { fieldValue } = useLinksField();

return (
<LinksDisplay
value={fieldValue}
anchorElement={cellElement}
isChipCountDisplayed={isCellSoftFocused}
withExpandedListBorder={fromTableCell}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ type MultiSelectFieldDisplayProps = {

export const MultiSelectFieldDisplay = ({
isCellSoftFocused,
cellElement,
fromTableCell,
}: MultiSelectFieldDisplayProps) => {
const { fieldValues, fieldDefinition } = useMultiSelectField();
Expand All @@ -26,7 +25,6 @@ export const MultiSelectFieldDisplay = ({

return (
<ExpandableList
anchorElement={cellElement}
isChipCountDisplayed={isCellSoftFocused}
withExpandedListBorder={fromTableCell}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@ import { getUrlHostName } from '~/utils/url/getUrlHostName';

type LinksDisplayProps = Pick<
ExpandableListProps,
'anchorElement' | 'isChipCountDisplayed' | 'withExpandedListBorder'
'isChipCountDisplayed' | 'withExpandedListBorder'
> & {
value?: FieldLinksValue;
};

export const LinksDisplay = ({
anchorElement,
isChipCountDisplayed,
withExpandedListBorder,
value,
Expand Down Expand Up @@ -55,7 +54,6 @@ export const LinksDisplay = ({

return (
<ExpandableList
anchorElement={anchorElement}
isChipCountDisplayed={isChipCountDisplayed}
withExpandedListBorder={withExpandedListBorder}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const StyledChipCount = styled(Chip)`
`;

export type ExpandableListProps = {
anchorElement?: HTMLElement;
isChipCountDisplayed?: boolean;
withExpandedListBorder?: boolean;
};
Expand All @@ -53,7 +52,6 @@ export type ChildrenProperty = {

export const ExpandableList = ({
children,
anchorElement,
isChipCountDisplayed: isChipCountDisplayedFromProps,
withExpandedListBorder = false,
}: {
Expand All @@ -75,10 +73,10 @@ export const ExpandableList = ({
// @see https://floating-ui.com/docs/useFloating#elements
const [childrenContainerElement, setChildrenContainerElement] =
useState<HTMLDivElement | null>(null);

const [previousChildrenContainerWidth, setPreviousChildrenContainerWidth] =
useState(childrenContainerElement?.clientWidth ?? 0);

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

const [firstHiddenChildIndex, setFirstHiddenChildIndex] = useState(
Expand Down Expand Up @@ -165,7 +163,7 @@ export const ExpandableList = ({
)}
{isListExpanded && (
<ExpandedListDropdown
anchorElement={anchorElement ?? childrenContainerElement ?? undefined}
anchorElement={containerRef.current ?? undefined}
onClickOutside={() => {
resetFirstHiddenChildIndex();
setIsListExpanded(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const ExpandedListDropdown = ({
const { refs, floatingStyles } = useFloating({
// @ts-expect-error placement accepts 'start' as value even if the typing does not permit it
placement: 'start',
middleware: [offset({ mainAxis: -1, crossAxis: -1 })],
middleware: [offset({ mainAxis: -9, crossAxis: -7 })],
elements: { reference: anchorElement },
});

Expand Down
Loading