-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Increase the usability of the manual commission flow #3079
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
Changes from all commits
dbbadd8
ec7feab
a090917
f3d0a37
c6af6e9
aeabf04
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import { cn } from "@dub/utils"; | ||
| import { Command, CommandInput, CommandItem, useCommandState } from "cmdk"; | ||
| import { Command, useCommandState } from "cmdk"; | ||
| import { ChevronDown } from "lucide-react"; | ||
| import { | ||
| forwardRef, | ||
|
|
@@ -200,6 +200,35 @@ export function Combobox({ | |
|
|
||
| useEffect(() => onSearchChange?.(search), [search]); | ||
|
|
||
| const createOptionItem = ( | ||
| <Command.Item | ||
| className={cn( | ||
| "flex cursor-pointer items-center gap-3 whitespace-nowrap rounded-md px-3 py-2 text-left text-sm text-neutral-700", | ||
| "data-[selected=true]:bg-neutral-100", | ||
| optionClassName, | ||
| )} | ||
| onSelect={async () => { | ||
| setIsCreating(true); | ||
| const success = await onCreate?.(search); | ||
| if (success) { | ||
| setSearch(""); | ||
| setIsOpen(false); | ||
| } | ||
| setIsCreating(false); | ||
| }} | ||
| > | ||
| {isCreating ? ( | ||
| <LoadingSpinner className="size-4 shrink-0" /> | ||
| ) : ( | ||
| <CreateIcon className="size-4 shrink-0" /> | ||
| )} | ||
| <div className="grow truncate"> | ||
| {createLabel?.(search) ?? | ||
| `Create ${search ? `"${search}"` : "new option..."}`} | ||
| </div> | ||
| </Command.Item> | ||
| ); | ||
|
|
||
| return ( | ||
| <Popover | ||
| openPopover={isOpen} | ||
|
|
@@ -225,7 +254,7 @@ export function Combobox({ | |
| <Command loop shouldFilter={shouldFilter}> | ||
| {!hideSearch && ( | ||
| <div className="flex items-center overflow-hidden rounded-t-lg border-b border-neutral-200"> | ||
| <CommandInput | ||
| <Command.Input | ||
| placeholder={searchPlaceholder} | ||
| value={search} | ||
| onValueChange={setSearch} | ||
|
|
@@ -252,7 +281,12 @@ export function Combobox({ | |
| )} | ||
| </div> | ||
| )} | ||
| <ScrollContainer className="max-h-[min(50vh,250px)]"> | ||
| <ScrollContainer | ||
| className={cn( | ||
| "max-h-[min(50vh,250px)]", | ||
| onCreate && !multiple && "max-h-[calc(min(50vh,250px)-3.5rem)]", | ||
| )} | ||
| > | ||
| <Command.List | ||
| className={cn("flex w-full min-w-[100px] flex-col gap-1 p-1")} | ||
| > | ||
|
|
@@ -271,33 +305,11 @@ export function Combobox({ | |
| className={optionClassName} | ||
| /> | ||
| ))} | ||
| {search.length > 0 && onCreate && ( | ||
| <CommandItem | ||
| className={cn( | ||
| "flex cursor-pointer items-center gap-3 whitespace-nowrap rounded-md px-3 py-2 text-left text-sm text-neutral-700", | ||
| "data-[selected=true]:bg-neutral-100", | ||
| optionClassName, | ||
| )} | ||
| onSelect={async () => { | ||
| setIsCreating(true); | ||
| const success = await onCreate?.(search); | ||
| if (success) { | ||
| setSearch(""); | ||
| setIsOpen(false); | ||
| } | ||
| setIsCreating(false); | ||
| }} | ||
| > | ||
| {isCreating ? ( | ||
| <LoadingSpinner className="size-4 shrink-0" /> | ||
| ) : ( | ||
| <CreateIcon className="size-4 shrink-0" /> | ||
| )} | ||
| <div className="grow truncate"> | ||
| {createLabel?.(search) || `Create "${search}"`} | ||
| </div> | ||
| </CommandItem> | ||
| )} | ||
| {/* for multiple selection, the create option item is shown at the bottom of the list */} | ||
| {onCreate && | ||
| multiple && | ||
| search.length > 0 && | ||
| createOptionItem} | ||
|
Comment on lines
+308
to
+312
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. π§© Analysis chainInconsistent create option visibility between selection modes. For multiple selection (line 312), the create option only appears when Is this intentional behavior? If so, consider documenting why the two modes differ. If not, add the same Also applies to: 334-339 π Script executed: #!/bin/bash
# Check if there are other usages or tests that might clarify this behavior
rg -n "onCreate.*multiple" --type=tsx --type=ts -C 3Length of output: 27 π Script executed: #!/bin/bash
# View the actual file to see both create option implementations
cat packages/ui/src/combobox/index.tsx | head -350 | tail -100Length of output: 4328 π Script executed: #!/bin/bash
# Search for onCreate usage without incorrect file type
rg -n "onCreate" packages/ui/src/combobox/ -A 5 -B 5Length of output: 4947 π Script executed: #!/bin/bash
# Search for tests related to combobox onCreate behavior
fd -e test -e spec | xargs grep -l "onCreate.*multiple\|multiple.*onCreate" 2>/dev/null | head -10Length of output: 0 π Script executed: #!/bin/bash
# Look for any tests in the combobox directory
fd "test|spec" packages/ui/src/combobox/Length of output: 0 π Script executed: #!/bin/bash
# View the createLabel and createOptionItem definitions
cat packages/ui/src/combobox/index.tsx | grep -n "createLabel\|createOptionItem" | head -20Length of output: 221 π Script executed: #!/bin/bash
# View the section where createLabel and createOptionItem are defined
cat packages/ui/src/combobox/index.tsx | sed -n '175,240p'Length of output: 1719 π Script executed: #!/bin/bash
# Search for any comments or documentation about the search.length behavior
rg -n "search.length" packages/ui/src/combobox/Length of output: 81 π Script executed: #!/bin/bash
# Look for README or documentation files in the combobox or ui package
fd "README\|CHANGELOG\|\.md$" packages/ui/src/combobox/ packages/ui/ | head -10Length of output: 0 Add consistent search.length check for single selection create option visibility. The multiple selection mode only displays the create option when Either add π€ Prompt for AI Agents |
||
| {shouldFilter ? ( | ||
| <Empty className="flex min-h-12 items-center justify-center text-sm text-neutral-500"> | ||
| {emptyState ? emptyState : "No matches"} | ||
|
|
@@ -318,6 +330,12 @@ export function Combobox({ | |
| )} | ||
| </Command.List> | ||
| </ScrollContainer> | ||
| {/* for single selection, the create option item is shown as a sticky item outside of the scroll container */} | ||
| {onCreate && !multiple && ( | ||
| <div className="rounded-b-lg border-t border-neutral-200 bg-white p-1"> | ||
| {createOptionItem} | ||
| </div> | ||
| )} | ||
| </Command> | ||
| </AnimatedSizeContainer> | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.