MCPcopy Create free account
hub / github.com/dailydotdev/apps / Dropdown

Function Dropdown

packages/shared/src/components/fields/Dropdown.tsx:65–304  ·  view source on GitHub ↗
({
  icon,
  className = {},
  selectedIndex,
  options,
  onChange,
  buttonAriaLabel,
  onOpenChange,
  shouldIndicateSelected,
  buttonSize = ButtonSize.Large,
  buttonVariant = ButtonVariant.Float,
  scrollable = false,
  renderItem,
  placeholder = '',
  iconOnly,
  drawerProps,
  openFullScreen,
  disabled,
  valid,
  hint,
  fetchNextPage,
  canFetchMore = false,
  isFetchingNextPage,
  ...props
}: DropdownProps)

Source from the content-addressed store, hash-verified

63}
64
65export function Dropdown({
66 icon,
67 className = {},
68 selectedIndex,
69 options,
70 onChange,
71 buttonAriaLabel,
72 onOpenChange,
73 shouldIndicateSelected,
74 buttonSize = ButtonSize.Large,
75 buttonVariant = ButtonVariant.Float,
76 scrollable = false,
77 renderItem,
78 placeholder = '',
79 iconOnly,
80 drawerProps,
81 openFullScreen,
82 disabled,
83 valid,
84 hint,
85 fetchNextPage,
86 canFetchMore = false,
87 isFetchingNextPage,
88 ...props
89}: DropdownProps): ReactElement {
90 const id = useId();
91 const isMobile = useViewSize(ViewSize.MobileL);
92 const [isVisible, setVisibility] = useState(false);
93 const wasVisible = usePrevious(`${isVisible}`);
94 const triggerRef = useRef<HTMLAnchorElement | HTMLButtonElement>(null);
95
96 useEffect(() => {
97 onOpenChange?.(isVisible);
98 }, [isVisible, onOpenChange]);
99
100 const handleMenuTrigger = (): void => {
101 setVisibility(!isVisible);
102 };
103
104 const handleChange = ({ value, index }: SelectParams): void => {
105 onChange(value, index);
106 };
107
108 const handleKeyboard = (event: React.KeyboardEvent): void => {
109 switch (event.key) {
110 case 'Enter':
111 case ' ':
112 event.preventDefault();
113 setVisibility(!isVisible);
114 break;
115 case 'Escape':
116 if (isVisible) {
117 setVisibility(false);
118 }
119 break;
120 default:
121 break;
122 }

Callers

nothing calls this directly

Calls 7

useViewSizeFunction · 0.90
usePreviousFunction · 0.90
onOpenChangeFunction · 0.85
useFeedInfiniteScrollFunction · 0.85
setVisibilityFunction · 0.85
renderButtonFunction · 0.70
handleChangeFunction · 0.70

Tested by

no test coverage detected