mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 23:24:21 +00:00
fix(webui): stabilize transcript menu interactions
This commit is contained in:
@@ -84,6 +84,20 @@ describe('FileBrowserContextMenu', () => {
|
||||
expect(open).toHaveBeenCalledWith(url, '_blank', 'noopener,noreferrer')
|
||||
})
|
||||
|
||||
it('keeps the menu open when the right button is released over Move to', () => {
|
||||
const onMoveTo = vi.fn()
|
||||
renderWithMenu(fileItem, { onMoveTo })
|
||||
|
||||
fireEvent.contextMenu(screen.getByTestId('context-trigger'))
|
||||
const moveTo = screen.getByRole('menuitem', { name: 'Move to' })
|
||||
fireEvent.pointerUp(moveTo, { button: 2, pointerType: 'mouse' })
|
||||
expect(onMoveTo).not.toHaveBeenCalled()
|
||||
expect(screen.getByRole('menu')).toBeTruthy()
|
||||
|
||||
fireEvent.click(moveTo)
|
||||
expect(onMoveTo).toHaveBeenCalledWith([fileItem])
|
||||
})
|
||||
|
||||
it('omits the new-tab action for a multi-item selection', () => {
|
||||
renderWithMenu(fileItem, {
|
||||
files: [fileItem, stackItem],
|
||||
|
||||
@@ -346,10 +346,6 @@ export function FileBrowserContextMenu({
|
||||
>
|
||||
{openInNewTabHref && (
|
||||
<ContextMenuItem
|
||||
onPointerUp={(event) => {
|
||||
// Radix can synthesize a click as the right button that opened the menu is released.
|
||||
if (event.button !== 0) event.preventDefault()
|
||||
}}
|
||||
onSelect={() => window.open(openInNewTabHref, '_blank', 'noopener,noreferrer')}
|
||||
>
|
||||
<ExternalLink className="mr-2 h-4 w-4" />
|
||||
|
||||
@@ -96,6 +96,17 @@ export function GenerateTranscriptsDialog({
|
||||
|
||||
<Combobox
|
||||
items={choices}
|
||||
onOpenChange={(isOpen, details) => {
|
||||
const activeElement = dialogRef.current?.ownerDocument.activeElement
|
||||
// WebKit can report focus-out after focus has already returned to the input.
|
||||
if (
|
||||
!isOpen &&
|
||||
details.reason === 'focus-out' &&
|
||||
activeElement === details.event.target
|
||||
) {
|
||||
details.cancel()
|
||||
}
|
||||
}}
|
||||
value={choices.find((choice) => choice.code === language)}
|
||||
onValueChange={(choice) => setLanguage(choice?.code ?? '')}
|
||||
itemToStringLabel={(choice) => choice.name}
|
||||
|
||||
@@ -95,6 +95,7 @@ function ContextMenuContent({
|
||||
function ContextMenuItem({
|
||||
className,
|
||||
inset,
|
||||
onPointerUp,
|
||||
variant = 'default',
|
||||
...props
|
||||
}: React.ComponentProps<typeof ContextMenuPrimitive.Item> & {
|
||||
@@ -106,6 +107,11 @@ function ContextMenuItem({
|
||||
data-slot="context-menu-item"
|
||||
data-inset={inset}
|
||||
data-variant={variant}
|
||||
onPointerUp={(event) => {
|
||||
// Radix can synthesize a click when the button that opened the menu is released.
|
||||
if (event.button !== 0) event.preventDefault()
|
||||
onPointerUp?.(event)
|
||||
}}
|
||||
className={cn(
|
||||
"relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",
|
||||
className,
|
||||
|
||||
Reference in New Issue
Block a user