Skip to content

Commit 4cae472

Browse files
scroll dropdown after n (#29)
1 parent 5c23021 commit 4cae472

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

components/KernDropdown.tsx

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { IconTrashXFilled } from '@tabler/icons-react';
99
import useOnClickOutside from '../hooks/useHooks/useOnClickOutside';
1010
import { useDefaults } from '../hooks/useDefaults';
1111
import SVGIcon from './SVGIcon';
12+
import { CSSProperties } from 'react';
1213

1314
const DEFAULTS = { fontSizeClass: 'text-xs' };
1415

@@ -77,6 +78,12 @@ export default function KernDropdown(props: KernDropdownProps) {
7778
}
7879
}, [props.positionDropdown]);
7980

81+
const scrollMaxStyles = useMemo((): CSSProperties => {
82+
if (!props.scrollAfterNOptions) return {};
83+
const maxHeight = 2 * props.scrollAfterNOptions + 0.5;
84+
return { "maxHeight": `${maxHeight}rem`, "overflowY": "auto" };
85+
}, [props.scrollAfterNOptions]);
86+
8087
function setOptionsWithCheckboxes(options: any[]) {
8188
if (selectedCheckboxes.length > 0) return;
8289
const newSelectedCheckboxes = options.map((option: any, index: number) => {
@@ -218,7 +225,7 @@ export default function KernDropdown(props: KernDropdownProps) {
218225
show={isOpen}
219226
>
220227
<Menu.Items className={`absolute z-10 mt-2 origin-top-right rounded-md bg-white shadow-sm ring-1 ring-black ring-opacity-5 focus:outline-none ${props.dropdownItemsWidth ?? 'w-full'} ${props.dropdownItemsClasses ?? ''} ${positionDropdown}`}>
221-
<div className="py-1">
228+
<div style={scrollMaxStyles} className='py-1'>
222229
{dropdownCaptions.map((option: any, index: number) => (
223230
<div key={option + "-" + index} className='relative'>
224231
<Menu.Item disabled={disabledOptions[index]}>

types/dropdown.ts

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export type KernDropdownProps = {
8383
filteredOptions?: (option: string) => void;
8484
ignoreDisabledForSearch?: boolean;
8585
positionDropdown?: "top" | "bottom" | "left" | "right";
86+
scrollAfterNOptions?: number;
8687
}
8788

8889
export type AppSelectionDropdownProps = {

0 commit comments

Comments
 (0)