Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

refactor(dify-ui): leave the enabled cursor to the app's base styles (#43981)

yyh4a528e9268e2
diff --git a/packages/dify-ui/docs/styling.md b/packages/dify-ui/docs/styling.md
index b2dd645274b..da84a59804d 100644
--- a/packages/dify-ui/docs/styling.md
+++ b/packages/dify-ui/docs/styling.md
@@ -73,6 +73,12 @@ Padding scrolls away with the content, so a scroll container with vertical paddi
sets matching scroll padding on the same element. Primitives own this pair. A call site adds the
height of a header or group label that must stay visible with the target item.
+## Cursor
+
+A control does not set a cursor for its enabled state; the consuming app's base styles decide it.
+A control sets a cursor only for a state it owns: `not-allowed` when disabled, the default arrow
+when read-only, and the text cursor on a text entry area.
+
## Focus indicator
`src/internal/focus.ts` owns the outer and inset focus-visible rings and the separated indicator
diff --git a/packages/dify-ui/src/autocomplete/index.stories.tsx b/packages/dify-ui/src/autocomplete/index.stories.tsx
index 7aabbd20741..17cbd53d421 100644
--- a/packages/dify-ui/src/autocomplete/index.stories.tsx
+++ b/packages/dify-ui/src/autocomplete/index.stories.tsx
@@ -17,6 +17,7 @@ import {
AutocompletePopup,
AutocompletePortal,
AutocompletePositioner,
+ AutocompleteRow,
AutocompleteSeparator,
AutocompleteStatus,
AutocompleteTrigger,
@@ -392,6 +393,126 @@ function BasicTagAutocomplete({ size = 'medium' }: { size?: 'small' | 'medium' |
)
}
+type IconOption = {
+ value: string
+ label: string
+ icon: string
+}
+
+const iconOptions: IconOption[] = [
+ { value: 'home', label: 'Home', icon: 'i-ri-home-line' },
+ { value: 'search', label: 'Search', icon: 'i-ri-search-line' },
+ { value: 'settings', label: 'Settings', icon: 'i-ri-settings-3-line' },
+ { value: 'user', label: 'User', icon: 'i-ri-user-line' },
+ { value: 'folder', label: 'Folder', icon: 'i-ri-folder-line' },
+ { value: 'document', label: 'Document', icon: 'i-ri-file-text-line' },
+ { value: 'image', label: 'Image', icon: 'i-ri-image-line' },
+ { value: 'calendar', label: 'Calendar', icon: 'i-ri-calendar-line' },
+ { value: 'clock', label: 'Clock', icon: 'i-ri-time-line' },
+ { value: 'mail', label: 'Mail', icon: 'i-ri-mail-line' },
+ { value: 'chat', label: 'Chat', icon: 'i-ri-chat-3-line' },
+ { value: 'notification', label: 'Notification', icon: 'i-ri-notification-3-line' },
+ { value: 'star', label: 'Star', icon: 'i-ri-star-line' },
+ { value: 'heart', label: 'Heart', icon: 'i-ri-heart-line' },
+ { value: 'bookmark', label: 'Bookmark', icon: 'i-ri-bookmark-line' },
+ { value: 'lock', label: 'Lock', icon: 'i-ri-lock-line' },
+ { value: 'key', label: 'Key', icon: 'i-ri-key-2-line' },
+ { value: 'link', label: 'Link', icon: 'i-ri-link' },
+ { value: 'attachment', label: 'Attachment', icon: 'i-ri-attachment-2' },
+ { value: 'download', label: 'Download', icon: 'i-ri-download-line' },
+ { value: 'upload', label: 'Upload', icon: 'i-ri-upload-line' },
+ { value: 'share', label: 'Share', icon: 'i-ri-share-line' },
+ { value: 'edit', label: 'Edit', icon: 'i-ri-edit-line' },
+ { value: 'delete', label: 'Delete', icon: 'i-ri-delete-bin-line' },
+ { value: 'code', label: 'Code', icon: 'i-ri-code-line' },
+ { value: 'terminal', label: 'Terminal', icon: 'i-ri-terminal-box-line' },
+ { value: 'database', label: 'Database', icon: 'i-ri-database-2-line' },
+ { value: 'cloud', label: 'Cloud', icon: 'i-ri-cloud-line' },
+ { value: 'globe', label: 'Globe', icon: 'i-ri-global-line' },
+ { value: 'location', label: 'Location', icon: 'i-ri-map-pin-line' },
+ { value: 'lightning', label: 'Lightning', icon: 'i-ri-flashlight-line' },
+ { value: 'robot', label: 'Robot', icon: 'i-ri-robot-2-line' },
+]
+
+const iconGridColumns = 8
+
+const getIconLabel = (item: IconOption) => item.label
+
+function IconGridList({
+ selected,
+ onSelect,
+}: {
+ selected: string
+ onSelect: (value: string) => void
+}) {
+ const items = useAutocompleteFilteredItems<IconOption>()
+ const rows = Array.from({ length: Math.ceil(items.length / iconGridColumns) }, (_, rowIndex) =>
+ items.slice(rowIndex * iconGridColumns, (rowIndex + 1) * iconGridColumns),
+ )
+
+ return (
+ <AutocompleteList aria-label="Icons" className="flex max-h-none flex-col gap-1 p-0">
+ {rows.map((row) => (
+ <AutocompleteRow key={row[0]?.value} className="grid grid-cols-8 gap-1">
+ {row.map((item) => (
+ <AutocompleteItem
+ key={item.value}
+ value={item}
+ aria-label={item.label}
+ onClick={() => onSelect(item.value)}
+ className={cn(
+ 'size-8 min-h-0 justify-center p-0',
+ selected === item.value &&
+ 'ring-[1.5px] ring-components-option-card-option-selected-border ring-inset',
+ )}
+ >
+ <span className={cn(item.icon, 'size-4 text-text-secondary')} aria-hidden="true" />
+ </AutocompleteItem>
+ ))}
+ </AutocompleteRow>
+ ))}
+ </AutocompleteList>
+ )
+}
+
+function IconGridDemo() {
+ const [search, setSearch] = React.useState('')
+ const [selected, setSelected] = React.useState('home')
+
+ return (
+ <div className="w-80 rounded-xl border border-divider-subtle bg-components-panel-bg p-3 shadow-xs">
+ <Autocomplete
+ open
+ inline
+ grid
+ autoHighlight
+ items={iconOptions}
+ itemToStringValue={getIconLabel}
+ value={search}
+ onValueChange={(next, details) => {
+ // Pressing an icon picks it; the query stays so the grid does not collapse to one match.
+ if (details.reason !== 'item-press') setSearch(next)
+ }}
+ >
+ <AutocompleteInputGroup className="mb-3">
+ <span
+ className="i-ri-search-line size-4 shrink-0 text-components-input-text-placeholder"
+ aria-hidden="true"
+ />
+ <AutocompleteInput
+ placeholder="Search icons…"
+ aria-label="Search icons"
+ aria-expanded="true"
+ />
+ <AutocompleteClear />
+ </AutocompleteInputGroup>
+ <IconGridList selected={selected} onSelect={setSelected} />
+ <AutocompleteEmpty className="p-0 text-text-tertiary">No icon matches.</AutocompleteEmpty>
+ </Autocomplete>
+ </div>
+ )
+}
+
function GroupedSuggestionList() {
const groups = useAutocompleteFilteredItems<SuggestionGroup>()
@@ -794,6 +915,10 @@ export const GroupedSuggestions: Story = {
),
}
+export const IconGrid: Story = {
+ render: () => <IconGridDemo />,
+}
+
export const FuzzyMatching: Story = {
render: () => <FuzzyMatchingDemo />,
}
diff --git a/packages/dify-ui/src/autocomplete/index.tsx b/packages/dify-ui/src/autocomplete/index.tsx
index 22cc6aa94b9..ae33ce983b3 100644
--- a/packages/dify-ui/src/autocomplete/index.tsx
+++ b/packages/dify-ui/src/autocomplete/index.tsx
@@ -86,7 +86,7 @@ const autocompleteListClassName = [
]
const autocompleteItemClassName = [
- 'flex min-h-8 cursor-pointer select-none items-center gap-2 rounded-lg px-2 py-1.5 text-text-secondary outline-hidden',
+ 'flex min-h-8 select-none items-center gap-2 rounded-lg px-2 py-1.5 text-text-secondary outline-hidden',
'data-highlighted:bg-state-base-hover data-highlighted:text-text-primary',
'data-disabled:cursor-not-allowed data-disabled:opacity-30',
]
diff --git a/packages/dify-ui/src/button/index.tsx b/packages/dify-ui/src/button/index.tsx
index 43d8ae755f6..35354f0c543 100644
--- a/packages/dify-ui/src/button/index.tsx
+++ b/packages/dify-ui/src/button/index.tsx
@@ -10,7 +10,7 @@ import { resolveClassName } from '../internal/resolve-class-name'
const buttonVariants = cva(
[
focusRingClassName,
- 'inline-flex cursor-pointer items-center justify-center overflow-hidden whitespace-nowrap data-disabled:cursor-not-allowed',
+ 'inline-flex items-center justify-center overflow-hidden whitespace-nowrap data-disabled:cursor-not-allowed',
],
{
variants: {
diff --git a/packages/dify-ui/src/combobox/index.tsx b/packages/dify-ui/src/combobox/index.tsx
index 6f88a3fae5e..cf428734d12 100644
--- a/packages/dify-ui/src/combobox/index.tsx
+++ b/packages/dify-ui/src/combobox/index.tsx
@@ -94,7 +94,7 @@ const comboboxListClassName = [
]
const comboboxItemClassName = [
- 'grid min-h-8 cursor-pointer select-none grid-cols-[1fr_auto] items-center gap-2 rounded-lg px-2 py-1.5 text-text-secondary outline-hidden',
+ 'grid min-h-8 select-none grid-cols-[1fr_auto] items-center gap-2 rounded-lg px-2 py-1.5 text-text-secondary outline-hidden',
'hover:bg-state-base-hover-alt hover:text-text-primary',
'data-highlighted:bg-state-base-hover data-highlighted:text-text-primary',
'data-selected:text-text-primary',
diff --git a/packages/dify-ui/src/date-time/internal/picker-parts.tsx b/packages/dify-ui/src/date-time/internal/picker-parts.tsx
index 6f4b50dc844..eed9eb3d5e9 100644
--- a/packages/dify-ui/src/date-time/internal/picker-parts.tsx
+++ b/packages/dify-ui/src/date-time/internal/picker-parts.tsx
@@ -283,7 +283,7 @@ function PickerTrigger({
'flex h-8 w-63 max-w-full items-center justify-between gap-0.5 rounded-lg bg-components-input-bg-normal ps-3 pe-2 text-start system-sm-regular text-components-input-text-filled',
'hover:bg-state-base-hover-alt data-popup-open:bg-state-base-hover-alt',
'aria-invalid:not-data-disabled:bg-components-input-bg-destructive aria-invalid:not-data-disabled:inset-ring-1 aria-invalid:not-data-disabled:inset-ring-components-input-border-destructive',
- 'data-disabled:cursor-not-allowed data-disabled:bg-components-input-bg-disabled',
+ 'aria-disabled:not-data-disabled:cursor-default data-disabled:cursor-not-allowed data-disabled:bg-components-input-bg-disabled',
!field.serializedValue && 'text-text-tertiary in-data-[theme=dark]:text-text-secondary',
resolveClassName(className, state),
)
diff --git a/packages/dify-ui/src/file-tree/index.tsx b/packages/dify-ui/src/file-tree/index.tsx
index 30e2afee97b..f98a9d68ddb 100644
--- a/packages/dify-ui/src/file-tree/index.tsx
+++ b/packages/dify-ui/src/file-tree/index.tsx
@@ -26,7 +26,7 @@ type FileTreeFileState = {
function fileTreeRowClassName({ className }: { className?: string }) {
return cn(
- 'group/file-tree-row relative flex h-6 w-full min-w-0 cursor-pointer items-center rounded-md ps-2 pe-1.5 text-start select-none',
+ 'group/file-tree-row relative flex h-6 w-full min-w-0 items-center rounded-md ps-2 pe-1.5 text-start select-none',
'hover:bg-state-base-hover',
insetFocusRingClassName,
'data-selected:bg-state-base-active',
@@ -94,7 +94,6 @@ function FileTreeFolderTrigger({
<BaseCollapsible.Trigger
className={(state) => fileTreeRowClassName({ className: resolveClassName(className, state) })}
disabled={disabled}
- data-disabled={disabled || undefined}
{...props}
>
{renderGuides(level)}
diff --git a/packages/dify-ui/src/icon-button/index.tsx b/packages/dify-ui/src/icon-button/index.tsx
index c653573eb95..b15d6c950cc 100644
--- a/packages/dify-ui/src/icon-button/index.tsx
+++ b/packages/dify-ui/src/icon-button/index.tsx
@@ -9,10 +9,7 @@ import { focusRingClassName } from '../internal/focus'
import { resolveClassName } from '../internal/resolve-class-name'
const iconButtonVariants = cva(
- [
- focusRingClassName,
- 'inline-flex cursor-pointer items-center justify-center data-disabled:cursor-not-allowed',
- ],
+ [focusRingClassName, 'inline-flex items-center justify-center data-disabled:cursor-not-allowed'],
{
variants: {
variant: {
diff --git a/packages/dify-ui/src/internal/menu.ts b/packages/dify-ui/src/internal/menu.ts
index 94905f73201..c9280740b51 100644
--- a/packages/dify-ui/src/internal/menu.ts
+++ b/packages/dify-ui/src/internal/menu.ts
@@ -1,7 +1,7 @@
export type MenuItemVariant = 'default' | 'destructive'
export const menuItemClassName =
- 'mx-1 flex h-8 cursor-pointer select-none items-center gap-1 rounded-lg px-2 outline-hidden data-highlighted:bg-state-base-hover data-disabled:cursor-not-allowed data-disabled:opacity-30'
+ 'mx-1 flex h-8 select-none items-center gap-1 rounded-lg px-2 outline-hidden data-highlighted:bg-state-base-hover data-disabled:cursor-not-allowed data-disabled:opacity-30'
export const menuItemDestructiveClassName =
'data-[variant=destructive]:text-text-destructive data-[variant=destructive]:data-highlighted:bg-state-destructive-hover'
diff --git a/packages/dify-ui/src/select/index.tsx b/packages/dify-ui/src/select/index.tsx
index 2439470f4c0..a34bbe09b3b 100644
--- a/packages/dify-ui/src/select/index.tsx
+++ b/packages/dify-ui/src/select/index.tsx
@@ -249,7 +249,7 @@ function SelectItem<Value = unknown>({ className, ...props }: SelectItemProps<Va
<BaseSelect.Item
className={(state) =>
cn(
- 'flex h-8 cursor-pointer items-center rounded-lg px-2 system-sm-medium text-text-secondary outline-hidden',
+ 'flex h-8 items-center rounded-lg px-2 system-sm-medium text-text-secondary outline-hidden',
'data-disabled:cursor-not-allowed data-disabled:opacity-50 data-highlighted:bg-state-base-hover',
resolveClassName(className, state),
)
diff --git a/packages/dify-ui/src/switch/index.tsx b/packages/dify-ui/src/switch/index.tsx
index 3577819c859..9cd4e0a2f78 100644
--- a/packages/dify-ui/src/switch/index.tsx
+++ b/packages/dify-ui/src/switch/index.tsx
@@ -10,7 +10,7 @@ import { resolveClassName } from '../internal/resolve-class-name'
const switchRootVariants = cva(
[
- 'group relative inline-flex shrink-0 cursor-pointer touch-manipulation items-center transition-colors duration-200 ease-in-out motion-reduce:transition-none',
+ 'group relative inline-flex shrink-0 touch-manipulation items-center transition-colors duration-200 ease-in-out motion-reduce:transition-none',
checkedControlFocusClassName,
'bg-components-toggle-bg-unchecked hover:bg-components-toggle-bg-unchecked-hover data-checked:bg-components-toggle-bg data-checked:hover:bg-components-toggle-bg-hover',
'data-disabled:cursor-not-allowed data-disabled:bg-components-toggle-bg-unchecked-disabled data-disabled:hover:bg-components-toggle-bg-unchecked-disabled data-disabled:data-checked:bg-components-toggle-bg-disabled data-disabled:data-checked:hover:bg-components-toggle-bg-disabled',
diff --git a/packages/dify-ui/src/tabs/index.tsx b/packages/dify-ui/src/tabs/index.tsx
index 74aeeb08e55..ea277bff822 100644
--- a/packages/dify-ui/src/tabs/index.tsx
+++ b/packages/dify-ui/src/tabs/index.tsx
@@ -29,7 +29,7 @@ function TabsTab({ className, ...props }: TabsTabProps) {
className={(state) =>
cn(
focusRingClassName,
- 'relative flex cursor-pointer touch-manipulation items-center border-b-2 border-transparent pt-2.5 pb-2 system-md-semibold text-text-tertiary data-active:border-components-tab-active data-active:text-text-primary data-disabled:cursor-not-allowed data-disabled:text-text-tertiary data-disabled:opacity-30 data-active:data-disabled:text-text-primary',
+ 'relative flex touch-manipulation items-center border-b-2 border-transparent pt-2.5 pb-2 system-md-semibold text-text-tertiary data-active:border-components-tab-active data-active:text-text-primary data-disabled:cursor-not-allowed data-disabled:text-text-tertiary data-disabled:opacity-30 data-active:data-disabled:text-text-primary',
resolveClassName(className, state),
)
}
diff --git a/web/app/components/app/create-from-dsl-modal/__tests__/index.spec.tsx b/web/app/components/app/create-from-dsl-modal/__tests__/index.spec.tsx
index 1c03656945a..f8b0513da20 100644
--- a/web/app/components/app/create-from-dsl-modal/__tests__/index.spec.tsx
+++ b/web/app/components/app/create-from-dsl-modal/__tests__/index.spec.tsx
@@ -225,9 +225,8 @@ describe('CreateFromDSLModal', () => {
})
})
- it('should switch tabs, close from the header icon, and ignore shortcuts without valid input', async () => {
- const handleClose = vi.fn()
- render(<CreateFromDSLModal show onClose={handleClose} />)
+ it('should switch tabs and ignore shortcuts without valid input', async () => {
+ render(<CreateFromDSLModal show onClose={vi.fn()} />)
submitWithKeyboard()
expect(mockImportDSL).not.toHaveBeenCalled()
@@ -238,12 +237,6 @@ describe('CreateFromDSLModal', () => {
expect(
screen.getByPlaceholderText(/(?:^|\.)importAppUrlPlaceholder(?=$|:)/),
)!.toBeInTheDocument()
-
- const closeTrigger = screen
- .getByText(/(?:^|\.)importApp(?=$|:)/)
- .parentElement?.querySelector('.cursor-pointer.items-center') as HTMLElement
- fireEvent.click(closeTrigger)
- expect(handleClose).toHaveBeenCalledTimes(1)
})
it('should expose the URL as a named form field', () => {
diff --git a/web/app/styles/preflight.css b/web/app/styles/preflight.css
index 4391401239c..e57ab4f97f5 100644
--- a/web/app/styles/preflight.css
+++ b/web/app/styles/preflight.css
@@ -350,7 +350,8 @@ textarea::placeholder {
}
/*
-Set the default cursor for buttons.
+Set the default cursor for buttons and for controls that act on a press.
+Dify UI leaves the enabled cursor to this rule, so a role its controls render belongs here.
*/
button,
@@ -358,6 +359,26 @@ button,
cursor: pointer;
}
+:is(
+ [role='switch'],
+ [role='checkbox'],
+ [role='radio'],
+ [role='tab'],
+ [role='option'],
+ [role='menuitem'],
+ [role='menuitemcheckbox'],
+ [role='menuitemradio']
+):not(:disabled, [aria-disabled='true'], [aria-readonly='true'], [data-disabled], [data-readonly]) {
+ cursor: pointer;
+}
+
+/*
+An item laid out in a grid takes the gridcell role. A cell that holds its own button or link is not the control.
+*/
+[role='gridcell']:not(:has(button, a), [aria-disabled='true'], [data-disabled]) {
+ cursor: pointer;
+}
+
/*
Make sure disabled buttons don't get the pointer cursor.
*/