fix(SingleEntitySelectMenuItems): extract Add New button from entitiesToSelect (#8474)
# Description Closes #8169 Extract Add New button from entitiesToSelect and add it as a separate element . There doesn't seem to be a point in having Add New as part of a list, it seems better off in its own component, apart from list items ## Rationale There already is #8353 addressing the same issue, but it seems it doesn't really remove the duplicate "Add New" in the list, leaving a duplicate "Add New" in `SingleEntitySelect` --------- Co-authored-by: Félix Malfait <felix@twenty.com>
This commit is contained in:
@ -7,7 +7,7 @@ import {
|
||||
size,
|
||||
useFloating,
|
||||
} from '@floating-ui/react';
|
||||
import { MouseEvent, ReactNode, useRef } from 'react';
|
||||
import { MouseEvent, ReactNode, useEffect, useRef } from 'react';
|
||||
import { Keys } from 'react-hotkeys-hook';
|
||||
import { Key } from 'ts-key-enum';
|
||||
|
||||
@ -65,8 +65,13 @@ export const Dropdown = ({
|
||||
}: DropdownProps) => {
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const { isDropdownOpen, toggleDropdown, closeDropdown, dropdownWidth } =
|
||||
useDropdown(dropdownId);
|
||||
const {
|
||||
isDropdownOpen,
|
||||
toggleDropdown,
|
||||
closeDropdown,
|
||||
dropdownWidth,
|
||||
setDropdownPlacement,
|
||||
} = useDropdown(dropdownId);
|
||||
|
||||
const offsetMiddlewares = [];
|
||||
|
||||
@ -78,7 +83,7 @@ export const Dropdown = ({
|
||||
offsetMiddlewares.push(offset({ mainAxis: dropdownOffset.y }));
|
||||
}
|
||||
|
||||
const { refs, floatingStyles } = useFloating({
|
||||
const { refs, floatingStyles, placement } = useFloating({
|
||||
placement: dropdownPlacement,
|
||||
middleware: [
|
||||
flip(),
|
||||
@ -100,6 +105,10 @@ export const Dropdown = ({
|
||||
strategy: dropdownStrategy,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
setDropdownPlacement(placement);
|
||||
}, [placement, setDropdownPlacement]);
|
||||
|
||||
const handleHotkeyTriggered = () => {
|
||||
toggleDropdown();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user