From 3cf67875272eafc69bb544af7edf063951fd303f Mon Sep 17 00:00:00 2001 From: Anup Cowkur Date: Tue, 10 Dec 2024 16:17:38 +0530 Subject: [PATCH] feat(frontend): make whole checkbox container clickable in dropdown select component closes #1560 --- .../app/components/dropdown_select.tsx | 66 ++++++++++++++++--- 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/frontend/dashboard/app/components/dropdown_select.tsx b/frontend/dashboard/app/components/dropdown_select.tsx index 220453361..a64c67a2f 100644 --- a/frontend/dashboard/app/components/dropdown_select.tsx +++ b/frontend/dashboard/app/components/dropdown_select.tsx @@ -141,8 +141,8 @@ const DropdownSelect: React.FC = ({ title, type, items, ini const buttonStyle = "block px-2 py-2 w-full truncate text-white bg-neutral-950 hover:text-black font-display text-left hover:bg-yellow-200 active:bg-yellow-300 outline-none focus:bg-yellow-200" const groupSelectButtonStyle = "text-white text-xs font-display rounded-md border border-white p-1 bg-neutral-950 hover:text-black hover:bg-yellow-200 hover:border-black focus-visible:bg-yellow-200 focus-visible:text-black focus-visible:border-black active:bg-yellow-300 outline-none" - const checkboxContainerStyle = "px-2 py-2 bg-neutral-950 truncate text-white hover:text-black hover:bg-yellow-200 font-display text-left" - const checkboxInputStyle = "appearance-none border-white rounded-sm font-display bg-neutral-950 checked:bg-neutral-950 checked:hover:bg-neutral-950 checked:focus:bg-neutral-950 focus:ring-offset-yellow-200 focus:ring-0 checked:ring-1 checked:ring-white" + const checkboxContainerStyle = "px-2 py-2 bg-neutral-950 cursor-pointer truncate text-white font-display text-left outline-none hover:text-black hover:bg-yellow-200 focus:text-black focus:bg-yellow-200 active:bg-yellow-300" + const checkboxInputStyle = "appearance-none pointer-events-none border-white rounded-sm font-display bg-neutral-950 checked:bg-neutral-950 checked:hover:bg-neutral-950 checked:focus:bg-neutral-950 focus:ring-offset-yellow-200 focus:ring-0 checked:ring-1 checked:ring-white" const searchInputStyle = "w-full bg-neutral-950 text-white text-sm border border-white rounded-md focus-visible:ring-yellow-300 py-2 px-4 font-sans placeholder:text-gray-400" return ( @@ -264,13 +264,29 @@ const DropdownSelect: React.FC = ({ title, type, items, ini } {items.filter((item) => (item as string).toLocaleLowerCase().includes(searchText.toLocaleLowerCase())).map((item) => ( -
+
{ + toggleCheckboxStringItem(item as string); + (e.currentTarget as HTMLElement).blur() + }} + onKeyDown={(e) => { + if (e.key === 'Enter' || e.key === ' ') { + e.preventDefault() + toggleCheckboxStringItem(item as string) + } + }} + > { toggleCheckboxStringItem(item as string) }} + readOnly + tabIndex={-1} /> {item as string}
@@ -299,13 +315,29 @@ const DropdownSelect: React.FC = ({ title, type, items, ini
} {items.filter((item) => (item as OsVersion).displayName.toLocaleLowerCase().includes(searchText.toLocaleLowerCase())).map((item, idx) => ( -
+
{ + toggleCheckboxOsVersionItem(item as OsVersion); + (e.currentTarget as HTMLElement).blur() + }} + onKeyDown={(e) => { + if (e.key === 'Enter' || e.key === ' ') { + e.preventDefault() + toggleCheckboxOsVersionItem(item as OsVersion) + } + }} + > { toggleCheckboxOsVersionItem(item as OsVersion) }} + readOnly + tabIndex={-1} /> {(item as OsVersion).displayName}
@@ -341,15 +373,31 @@ const DropdownSelect: React.FC = ({ title, type, items, ini
} {items.filter((item) => (item as AppVersion).displayName.toLocaleLowerCase().includes(searchText.toLocaleLowerCase())).map((item) => ( -
+
{ + toggleCheckboxAppVersionItem(item as AppVersion); + (e.currentTarget as HTMLElement).blur() + }} + onKeyDown={(e) => { + if (e.key === 'Enter' || e.key === ' ') { + e.preventDefault() + toggleCheckboxAppVersionItem(item as AppVersion) + } + }} + > { toggleCheckboxAppVersionItem(item as AppVersion) }} + readOnly + tabIndex={-1} /> - {(item as AppVersion).displayName} + {(item as OsVersion).displayName}
))}
}