Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(design): unify control states and mobile field density (#8134)

白熱5cfea1118806
diff --git a/packages/design/src/components/accordion/Accordion.tsx b/packages/design/src/components/accordion/Accordion.tsx
index 94c349db62..fee5d1422b 100644
--- a/packages/design/src/components/accordion/Accordion.tsx
+++ b/packages/design/src/components/accordion/Accordion.tsx
@@ -17,6 +17,7 @@
import type { ReactNode } from 'react';
import { DownIcon } from '@univerjs/icons';
import { useState } from 'react';
+import { focusClassName } from '../../helper/class-utilities';
import { clsx } from '../../helper/clsx';
interface IAccordionItem {
@@ -57,15 +58,14 @@ export function Accordion(props: IAccordionProps) {
{items.map((item, index) => (
<div key={item.id ?? index}>
<button
- className={`
+ className={clsx(focusClassName, `
univer-box-border univer-flex univer-w-full univer-cursor-pointer univer-items-center
univer-gap-1.5 univer-border-none univer-bg-transparent univer-p-4 univer-text-left
univer-text-gray-700
hover:univer-text-gray-900
- focus:univer-outline-none
dark:!univer-text-gray-200
dark:hover:!univer-text-gray-0
- `}
+ `)}
type="button"
onClick={() => toggleItem(index)}
>
diff --git a/packages/design/src/components/avatar/Avatar.tsx b/packages/design/src/components/avatar/Avatar.tsx
index e2cc68b5f4..b0b5bc7183 100644
--- a/packages/design/src/components/avatar/Avatar.tsx
+++ b/packages/design/src/components/avatar/Avatar.tsx
@@ -24,7 +24,8 @@ type ImageFit = 'fill' | 'contain' | 'cover' | 'none' | 'scale-down';
const avatarVariants = cva(
`
univer-relative univer-inline-block univer-overflow-hidden univer-whitespace-nowrap univer-bg-gray-200
- univer-text-center univer-align-middle univer-text-gray-0
+ univer-text-center univer-align-middle univer-text-gray-700
+ dark:!univer-bg-gray-700 dark:!univer-text-gray-100
`,
{
variants: {
diff --git a/packages/design/src/components/badge/Badge.tsx b/packages/design/src/components/badge/Badge.tsx
index 04600d7a66..531cc9327c 100644
--- a/packages/design/src/components/badge/Badge.tsx
+++ b/packages/design/src/components/badge/Badge.tsx
@@ -17,6 +17,7 @@
import type { ReactNode } from 'react';
import { CloseIcon } from '@univerjs/icons';
import { useContext } from 'react';
+import { focusClassName, resetButtonClassName } from '../../helper/class-utilities';
import { clsx } from '../../helper/clsx';
import { ConfigContext } from '../config-provider/ConfigProvider';
@@ -50,11 +51,10 @@ export function Badge(props: IBadgeProps) {
{closable && (
<button
- className="
- univer-flex univer-cursor-pointer univer-items-center univer-justify-center univer-border-none
- univer-p-0 univer-outline-none univer-transition-opacity
+ className={clsx(resetButtonClassName, focusClassName, `
+ univer-rounded-sm univer-text-current univer-transition-opacity
hover:univer-opacity-70
- "
+ `)}
type="button"
aria-label={locale?.Accessibility.closeBadge}
onClick={onClose}
diff --git a/packages/design/src/components/button/Button.tsx b/packages/design/src/components/button/Button.tsx
index 68920d4e50..f7dcc4f523 100644
--- a/packages/design/src/components/button/Button.tsx
+++ b/packages/design/src/components/button/Button.tsx
@@ -19,6 +19,7 @@ import type { ButtonHTMLAttributes } from 'react';
import { Slot } from '@radix-ui/react-slot';
import { cva } from 'class-variance-authority';
import { forwardRef } from 'react';
+import { focusClassName } from '../../helper/class-utilities';
import { clsx } from '../../helper/clsx';
export const buttonVariants = cva(
@@ -46,9 +47,9 @@ export const buttonVariants = cva(
active:univer-bg-primary-700
`,
danger: `
- univer-border-red-500 univer-bg-red-500 univer-text-gray-0
- hover:univer-border-red-400 hover:univer-bg-red-400
- active:univer-border-red-600 active:univer-bg-red-600
+ univer-border-red-600 univer-bg-red-600 univer-text-gray-0
+ hover:univer-border-red-700 hover:univer-bg-red-700
+ active:univer-border-red-800 active:univer-bg-red-800
`,
text: `
univer-border-transparent univer-bg-transparent univer-text-gray-900
@@ -61,8 +62,11 @@ export const buttonVariants = cva(
link: `
univer-border-transparent univer-bg-transparent univer-text-primary-600 univer-decoration-current
univer-underline-offset-4
- hover:univer-text-primary-500 hover:univer-underline
+ hover:univer-text-primary-700 hover:univer-underline
active:univer-text-primary-700
+ dark:!univer-text-primary-300
+ dark:hover:!univer-text-primary-200
+ dark:active:!univer-text-primary-100
`,
ghost: `
univer-border-transparent univer-bg-transparent univer-text-gray-900
@@ -76,8 +80,8 @@ export const buttonVariants = cva(
size: {
icon: 'univer-size-8 !univer-p-0',
small: 'univer-h-6 univer-rounded-md univer-px-1.5 univer-text-xs',
- middle: 'univer-h-8 univer-rounded-lg univer-px-2 univer-text-sm',
- large: 'univer-h-10 univer-rounded-lg univer-px-3 univer-text-sm',
+ middle: 'univer-h-8 univer-rounded-md univer-px-2 univer-text-sm',
+ large: 'univer-h-10 univer-rounded-md univer-px-3 univer-text-sm',
},
},
defaultVariants: {
@@ -98,7 +102,7 @@ export const Button = forwardRef<HTMLButtonElement, IButtonProps>(
const Comp = asChild ? Slot : 'button';
return (
<Comp
- className={clsx(buttonVariants({ variant, size, className }))}
+ className={clsx(buttonVariants({ variant, size }), focusClassName, className)}
ref={ref}
data-u-comp="button"
{...props}
diff --git a/packages/design/src/components/calendar/Calendar.tsx b/packages/design/src/components/calendar/Calendar.tsx
index b40ae293dc..a9f701b28f 100644
--- a/packages/design/src/components/calendar/Calendar.tsx
+++ b/packages/design/src/components/calendar/Calendar.tsx
@@ -192,7 +192,7 @@ export function Calendar(props: ICalendarProps) {
dir={direction}
className={clsx(`
univer-mx-auto univer-max-w-xs univer-select-none univer-rounded univer-bg-gray-0 univer-text-gray-900
- dark:!univer-bg-gray-900 dark:!univer-text-gray-0
+ dark:!univer-bg-gray-700 dark:!univer-text-gray-0
`, className)}
>
<nav
diff --git a/packages/design/src/components/checkbox/Checkbox.tsx b/packages/design/src/components/checkbox/Checkbox.tsx
index 1c69e5e450..794240aa1c 100644
--- a/packages/design/src/components/checkbox/Checkbox.tsx
+++ b/packages/design/src/components/checkbox/Checkbox.tsx
@@ -97,7 +97,7 @@ export function Checkbox(props: ICheckboxProps) {
<span className="univer-relative univer-block">
<input
ref={inputRef}
- className="univer-absolute univer-size-0 univer-opacity-0"
+ className="univer-peer univer-sr-only"
type="checkbox"
checked={checked}
aria-checked={indeterminate ? 'mixed' : checked}
@@ -109,6 +109,9 @@ export function Checkbox(props: ICheckboxProps) {
univer-relative univer-box-border univer-flex univer-size-4 univer-items-center
univer-justify-center univer-overflow-hidden univer-rounded univer-border univer-border-solid
univer-transition-colors
+ peer-focus:univer-outline peer-focus:univer-outline-2 peer-focus:univer-outline-offset-2
+ peer-focus:univer-outline-primary-600
+ dark:peer-focus:!univer-outline-primary-300
`, {
'univer-opacity-50': disabled,
'univer-border-primary-600 univer-bg-primary-600': checked || indeterminate,
diff --git a/packages/design/src/components/color-picker/ColorInput.tsx b/packages/design/src/components/color-picker/ColorInput.tsx
index 7d271efcc0..e244f2fc96 100644
--- a/packages/design/src/components/color-picker/ColorInput.tsx
+++ b/packages/design/src/components/color-picker/ColorInput.tsx
@@ -79,7 +79,6 @@ function HexInput({ hsv, onChange }: IInputProps) {
<input
className={clsx(`
univer-w-full univer-min-w-0 univer-px-2 !univer-pl-4 univer-uppercase
- focus:univer-border-primary-500 focus:univer-outline-none
rtl:!univer-pl-2 rtl:!univer-pr-4
dark:!univer-text-gray-0
`, borderClassName)}
@@ -167,7 +166,6 @@ function RgbInput({ hsv, alpha, format, onChange }: IInputProps) {
className={`
univer-flex univer-items-center univer-gap-2
[&>input]:univer-w-11 [&>input]:univer-border-gray-200
- [&>input]:focus:univer-border-primary-500
dark:[&>input]:!univer-border-gray-600 dark:[&>input]:!univer-text-gray-0
`}
>
@@ -210,11 +208,15 @@ export function ColorInput({ hsv, alpha, format, onChange }: IColorInputProps) {
<div
className={`
univer-flex univer-gap-2
+ [&_input:focus]:!univer-border-primary-600 [&_input:focus]:univer-ring-2
+ [&_input:focus]:univer-ring-primary-50
+ dark:[&_input:focus]:!univer-border-primary-300 dark:[&_input:focus]:!univer-ring-primary-900
[&_input]:univer-box-border [&_input]:univer-flex [&_input]:univer-h-7 [&_input]:univer-items-center
- [&_input]:univer-rounded [&_input]:univer-border [&_input]:univer-border-solid
- [&_input]:univer-border-gray-200 [&_input]:univer-bg-transparent [&_input]:univer-px-1.5
+ [&_input]:univer-rounded-md [&_input]:univer-border [&_input]:univer-border-solid
+ [&_input]:univer-border-gray-200 [&_input]:univer-bg-gray-0 [&_input]:univer-px-1.5
[&_input]:univer-text-sm [&_input]:univer-text-gray-700 [&_input]:univer-outline-none
- dark:[&_input]:!univer-border-gray-600 dark:[&_input]:!univer-text-gray-0
+ dark:[&_input]:!univer-border-gray-600 dark:[&_input]:!univer-bg-gray-700
+ dark:[&_input]:!univer-text-gray-0
`}
>
<div className="univer-relative univer-flex univer-flex-1 univer-gap-2">
diff --git a/packages/design/src/components/command/Command.tsx b/packages/design/src/components/command/Command.tsx
index e9f89714aa..276de1ef74 100644
--- a/packages/design/src/components/command/Command.tsx
+++ b/packages/design/src/components/command/Command.tsx
@@ -73,7 +73,10 @@ export function CommandEmpty({ className, ...props }: ComponentProps<typeof Comm
return (
<CommandPrimitive.Empty
data-slot="command-empty"
- className={clsx('univer-py-6 univer-text-center univer-text-sm univer-text-gray-500', className)}
+ className={clsx(`
+ univer-py-6 univer-text-center univer-text-sm univer-text-gray-500
+ dark:!univer-text-gray-300
+ `, className)}
{...props}
/>
);
@@ -88,6 +91,7 @@ export function CommandGroup({ className, ...props }: ComponentProps<typeof Comm
[&_[cmdk-group-heading]]:univer-px-2 [&_[cmdk-group-heading]]:univer-py-1.5
[&_[cmdk-group-heading]]:univer-text-xs [&_[cmdk-group-heading]]:univer-font-medium
[&_[cmdk-group-heading]]:univer-text-gray-500
+ dark:[&_[cmdk-group-heading]]:!univer-text-gray-300
`, className)}
{...props}
/>
diff --git a/packages/design/src/components/config-provider/ConfigProvider.tsx b/packages/design/src/components/config-provider/ConfigProvider.tsx
index 8fd2db9b9e..2dfdf80f7a 100644
--- a/packages/design/src/components/config-provider/ConfigProvider.tsx
+++ b/packages/design/src/components/config-provider/ConfigProvider.tsx
@@ -16,13 +16,15 @@
import type { ReactNode } from 'react';
import { DirectionProvider } from '@radix-ui/react-direction';
-import { createContext, useMemo } from 'react';
+import { createContext, useContext, useMemo } from 'react';
import { isBrowser } from '../../helper/is-browser';
export interface IConfigProviderProps {
children: ReactNode;
locale?: any;
direction?: 'ltr' | 'rtl';
+ /** Default field density. Explicit component sizes take precedence. */
+ density?: 'default' | 'touch';
mountContainer: HTMLElement | null;
mobileKeyboardViewport?: IMobileKeyboardViewport | null;
}
@@ -39,7 +41,8 @@ export const ConfigContext = createContext<Omit<IConfigProviderProps, 'children'
});
export function ConfigProvider(props: IConfigProviderProps) {
- const { children, locale, mountContainer, direction, mobileKeyboardViewport } = props;
+ const parentConfig = useContext(ConfigContext);
+ const { children, locale, mountContainer, direction, mobileKeyboardViewport, density = parentConfig.density } = props;
const value = useMemo(() => {
return {
@@ -47,8 +50,9 @@ export function ConfigProvider(props: IConfigProviderProps) {
direction,
mountContainer,
mobileKeyboardViewport,
+ density,
};
- }, [locale, direction, mobileKeyboardViewport, mountContainer]);
+ }, [locale, direction, mobileKeyboardViewport, mountContainer, density]);
return (
<ConfigContext.Provider value={value}>
diff --git a/packages/design/src/components/config-provider/__tests__/index.spec.tsx b/packages/design/src/components/config-provider/__tests__/ConfigProvider.spec.tsx
similarity index 56%
rename from packages/design/src/components/config-provider/__tests__/index.spec.tsx
rename to packages/design/src/components/config-provider/__tests__/ConfigProvider.spec.tsx
index 9bb6a23f8a..77ae896918 100644
--- a/packages/design/src/components/config-provider/__tests__/index.spec.tsx
+++ b/packages/design/src/components/config-provider/__tests__/ConfigProvider.spec.tsx
@@ -14,11 +14,12 @@
* limitations under the License.
*/
-import type enUS from '../../../locale/en-US';
-import { cleanup, render } from '@testing-library/react';
+import { cleanup, fireEvent, render } from '@testing-library/react';
import { useContext } from 'react';
import { afterEach, describe, expect, it } from 'vitest';
+import type enUS from '../../../locale/en-US';
import zhCN from '../../../locale/zh-CN';
+import { InputNumber } from '../../input-number/InputNumber';
import { ConfigContext, ConfigProvider } from '../ConfigProvider';
afterEach(cleanup);
@@ -73,4 +74,36 @@ describe('ConfigProvider', () => {
root.unmount();
});
+
+ it('inherits touch density through nested providers and preserves explicit compact controls', () => {
+ const { getByRole, queryByRole, rerender } = render(
+ <ConfigProvider density="touch" mountContainer={document.body}>
+ <ConfigProvider locale={zhCN.design} mountContainer={document.body}>
+ <InputNumber aria-label="Paragraph spacing" min={0} defaultValue={12} />
+ </ConfigProvider>
+ </ConfigProvider>
+ );
+ expect(queryByRole('button', { name: zhCN.design.Accessibility.increment })).toBeNull();
+ const input = getByRole('textbox', { name: 'Paragraph spacing' }) as HTMLInputElement;
+ fireEvent.change(input, { target: { value: '18' } });
+ fireEvent.keyDown(input, { key: 'ArrowUp' });
+ expect(input.value).toBe('19');
+ expect(input.inputMode).toBe('decimal');
+
+ rerender(
+ <ConfigProvider density="touch" locale={zhCN.design} mountContainer={document.body}>
+ <InputNumber size="mini" defaultValue={12} />
+ </ConfigProvider>
+ );
+ expect(getByRole('button', { name: zhCN.design.Accessibility.increment })).toBeTruthy();
+
+ rerender(
+ <ConfigProvider density="touch" mountContainer={document.body}>
+ <ConfigProvider density="default" locale={zhCN.design} mountContainer={document.body}>
+ <InputNumber defaultValue={12} />
+ </ConfigProvider>
+ </ConfigProvider>
+ );
+ expect(getByRole('button', { name: zhCN.design.Accessibility.increment })).toBeTruthy();
+ });
});
diff --git a/packages/design/src/components/date-picker/DatePicker.tsx b/packages/design/src/components/date-picker/DatePicker.tsx
index 9c759b6246..f455a09f64 100644
--- a/packages/design/src/components/date-picker/DatePicker.tsx
+++ b/packages/design/src/components/date-picker/DatePicker.tsx
@@ -16,7 +16,7 @@
import { CalendarIcon } from '@univerjs/icons';
import { useState } from 'react';
-import { borderClassName } from '../../helper/class-utilities';
+import { borderClassName, focusClassName } from '../../helper/class-utilities';
import { clsx } from '../../helper/clsx';
import { formatDateWithPattern } from '../../helper/date';
import { Calendar } from '../calendar/Calendar';
@@ -62,11 +62,12 @@ export function DatePicker(props: IDatePickerProps) {
>
<button
className={clsx(`
- univer-flex univer-h-8 univer-items-center univer-justify-between univer-gap-2 univer-rounded-md
- univer-bg-transparent univer-px-2 univer-text-sm univer-text-gray-800 univer-transition-all
+ univer-box-border univer-flex univer-h-8 univer-items-center univer-justify-between univer-gap-2
+ univer-rounded-md univer-bg-gray-0 univer-px-2 univer-text-sm univer-text-gray-800
+ univer-transition-all
hover:univer-border-primary-600
- dark:!univer-text-gray-0
- `, borderClassName, className)}
+ dark:!univer-bg-gray-700 dark:!univer-text-gray-0
+ `, borderClassName, focusClassName, className)}
type="button"
>
{formatDateWithPattern(value, 'YYYY-MM-DD')}
diff --git a/packages/design/src/components/date-range-picker/DateRangePicker.tsx b/packages/design/src/components/date-range-picker/DateRangePicker.tsx
index 81886e44cd..eaf51cefd7 100644
--- a/packages/design/src/components/date-range-picker/DateRangePicker.tsx
+++ b/packages/design/src/components/date-range-picker/DateRangePicker.tsx
@@ -16,7 +16,7 @@
import { CalendarIcon } from '@univerjs/icons';
import { useState } from 'react';
-import { borderClassName } from '../../helper/class-utilities';
+import { borderClassName, focusClassName } from '../../helper/class-utilities';
import { clsx } from '../../helper/clsx';
import { formatDateWithPattern } from '../../helper/date';
import { Calendar } from '../calendar/Calendar';
@@ -82,11 +82,12 @@ export function DateRangePicker(props: IDateRangePickerProps) {
>
<button
className={clsx(`
- univer-flex univer-h-8 univer-items-center univer-justify-between univer-gap-2 univer-rounded-md
- univer-bg-transparent univer-px-2 univer-text-sm univer-text-gray-800 univer-transition-all
+ univer-box-border univer-flex univer-h-8 univer-items-center univer-justify-between univer-gap-2
+ univer-rounded-md univer-bg-gray-0 univer-px-2 univer-text-sm univer-text-gray-800
+ univer-transition-all
hover:univer-border-primary-600
- dark:!univer-text-gray-0
- `, borderClassName, className)}
+ dark:!univer-bg-gray-700 dark:!univer-text-gray-0
+ `, borderClassName, focusClassName, className)}
type="button"
>
<span className="univer-flex univer-gap-1">
diff --git a/packages/design/src/components/dialog/DialogPrimitive.tsx b/packages/design/src/components/dialog/DialogPrimitive.tsx
index 14a92cbf8d..cdf3670bb3 100644
--- a/packages/design/src/components/dialog/DialogPrimitive.tsx
+++ b/packages/design/src/components/dialog/DialogPrimitive.tsx
@@ -177,7 +177,10 @@ const DialogDescription = forwardRef<
>(({ className, ...props }, ref) => (
<Description
ref={ref}
- className={clsx('univer-text-sm univer-text-gray-500', className)}
+ className={clsx(`
+ univer-text-sm univer-text-gray-500
+ dark:!univer-text-gray-300
+ `, className)}
{...props}
/>
));
diff --git a/packages/design/src/components/dropdown-menu/DropdownMenuPrimitive.tsx b/packages/design/src/components/dropdown-menu/DropdownMenuPrimitive.tsx
index 417cd8b3b0..80e25344f3 100644
--- a/packages/design/src/components/dropdown-menu/DropdownMenuPrimitive.tsx
+++ b/packages/design/src/components/dropdown-menu/DropdownMenuPrimitive.tsx
@@ -255,7 +255,10 @@ function DropdownMenuCheckboxItem({
>
<ItemIndicator>
<CheckMarkIcon
- className="univer-block univer-size-4 univer-text-primary-600"
+ className="
+ univer-block univer-size-4 univer-text-primary-600
+ dark:!univer-text-primary-300
+ "
/>
</ItemIndicator>
</span>
@@ -300,7 +303,10 @@ function DropdownMenuRadioItem({
<ItemIndicator>
<CheckMarkIcon
- className="univer-block univer-size-4 univer-text-primary-600"
+ className="
+ univer-block univer-size-4 univer-text-primary-600
+ dark:!univer-text-primary-300
+ "
/>
</ItemIndicator>
</span>
diff --git a/packages/design/src/components/dropdown-menu/MobileDropdownMenu.tsx b/packages/design/src/components/dropdown-menu/MobileDropdownMenu.tsx
index c8aa09222b..279040ed45 100644
--- a/packages/design/src/components/dropdown-menu/MobileDropdownMenu.tsx
+++ b/packages/design/src/components/dropdown-menu/MobileDropdownMenu.tsx
@@ -15,8 +15,9 @@
*/
import type { ReactNode } from 'react';
-import type { DropdownMenuType, IDropdownMenuProps } from './DropdownMenu';
import { useState } from 'react';
+import type { DropdownMenuType, IDropdownMenuProps } from './DropdownMenu';
+import { focusClassName } from '../../helper/class-utilities';
import { clsx } from '../../helper/clsx';
import { MobileDropdownSurface } from '../dropdown/MobileDropdownSurface';
@@ -118,7 +119,12 @@ export function MobileDropdownMenu(props: IMobileDropdownMenuProps) {
}
return (
<div key={index} className="univer-flex univer-flex-col univer-gap-2">
- <div className="univer-px-4 univer-py-2 univer-text-sm univer-font-medium univer-text-gray-500">
+ <div
+ className="
+ univer-px-4 univer-py-2 univer-text-sm univer-font-medium univer-text-gray-500
+ dark:!univer-text-gray-300
+ "
+ >
{item.children}
</div>
{item.options?.map(renderMenuItem)}
@@ -126,6 +132,25 @@ export function MobileDropdownMenu(props: IMobileDropdownMenuProps) {
);
}
+ function mobileRowClassName(active: boolean): string {
+ return clsx(focusClassName, `
+ univer-flex univer-h-12 univer-w-full univer-items-center univer-rounded-xl univer-border-0 univer-px-4
+ univer-text-left univer-text-base univer-text-gray-900
+ active:univer-bg-gray-200
+ disabled:univer-opacity-40
+ dark:!univer-text-gray-0
+ dark:active:!univer-bg-gray-700
+ `, active
+ ? `
+ univer-bg-primary-50 univer-text-primary-600
+ dark:!univer-bg-primary-900 dark:!univer-text-primary-100
+ `
+ : `
+ univer-bg-gray-0
+ dark:!univer-bg-gray-800
+ `);
+ }
+
return (
<MobileDropdownSurface
open={open}
@@ -137,22 +162,3 @@ export function MobileDropdownMenu(props: IMobileDropdownMenuProps) {
</MobileDropdownSurface>
);
}
-
-function mobileRowClassName(active: boolean): string {
- return clsx(`
- univer-flex univer-h-12 univer-w-full univer-items-center univer-rounded-xl univer-border-0 univer-px-4
- univer-text-left univer-text-base univer-text-gray-900 univer-outline-none
- active:univer-bg-gray-200
- disabled:univer-opacity-40
- dark:!univer-text-gray-0
- dark:active:!univer-bg-gray-700
- `, active
- ? `
- univer-bg-primary-50
- dark:!univer-bg-gray-700
- `
- : `
- univer-bg-gray-0
- dark:!univer-bg-gray-800
- `);
-}
diff --git a/packages/design/src/components/dropdown/PopoverPrimitive.tsx b/packages/design/src/components/dropdown/PopoverPrimitive.tsx
index 8b3019f1a6..e270c0439c 100644
--- a/packages/design/src/components/dropdown/PopoverPrimitive.tsx
+++ b/packages/design/src/components/dropdown/PopoverPrimitive.tsx
@@ -56,7 +56,7 @@ function PopoverContent({
univer-z-[1080] univer-max-h-[--radix-popper-available-height] univer-overflow-y-auto
univer-rounded-md univer-bg-gray-0 univer-text-gray-900 univer-shadow-md univer-outline-none
data-[state=closed]:univer-pointer-events-none
- dark:!univer-bg-gray-900 dark:!univer-text-gray-0
+ dark:!univer-bg-gray-700 dark:!univer-text-gray-0
dark:focus-visible:!univer-border-gray-600
`,
borderClassName,
diff --git a/packages/design/src/components/form-layout/FormLayout.tsx b/packages/design/src/components/form-layout/FormLayout.tsx
index 722f88b86e..b365ca5df6 100644
--- a/packages/design/src/components/form-layout/FormLayout.tsx
+++ b/packages/design/src/components/form-layout/FormLayout.tsx
@@ -32,14 +32,14 @@ export interface IFormLayoutProps {
defaultCollapsed?: boolean;
}
-const FormLayoutContext = createContext(false);
+export const FormLayoutContext = createContext(false);
export const FormLayout = (props: IFormLayoutProps) => {
const { label, desc, children, style, className, error, contentStyle, collapsable = false, defaultCollapsed = false } = props;
const [collapsed, setCollapsed] = useState(defaultCollapsed);
return (
- <FormLayoutContext.Provider value>
+ <FormLayoutContext.Provider value={Boolean(error)}>
<div data-u-comp="form-layout" className={clsx('univer-mb-3 univer-flex univer-flex-col', className)} style={style}>
{label && (
<div
@@ -79,20 +79,22 @@ export const FormLayout = (props: IFormLayoutProps) => {
{children
? (
<div
- className={clsx(`
+ className={`
last:univer-mb-0
[&_[data-u-comp=input]]:univer-w-full
[&_[data-u-comp=select]]:univer-w-full
- `, {
- '[&_[data-u-comp=input]]:univer-border-red-500': error,
- '[&_[data-u-comp=select]]:univer-border-red-500': error,
- })}
+ `}
style={contentStyle}
>
{children}
{error
? (
- <div className="univer-mt-1 univer-text-xs univer-text-red-500">
+ <div
+ className="
+ univer-mt-1 univer-text-xs univer-text-red-600
+ dark:!univer-text-red-400
+ "
+ >
{error}
</div>
)
diff --git a/packages/design/src/components/form-layout/__tests__/index.spec.tsx b/packages/design/src/components/form-layout/__tests__/FormLayout.spec.tsx
similarity index 60%
rename from packages/design/src/components/form-layout/__tests__/index.spec.tsx
rename to packages/design/src/components/form-layout/__tests__/FormLayout.spec.tsx
index 97b3b9d272..5f8926d38e 100644
--- a/packages/design/src/components/form-layout/__tests__/index.spec.tsx
+++ b/packages/design/src/components/form-layout/__tests__/FormLayout.spec.tsx
@@ -16,6 +16,10 @@
import { cleanup, fireEvent, render, screen } from '@testing-library/react';
import { afterEach, describe, expect, it } from 'vitest';
+import { InputNumber } from '../../input-number/InputNumber';
+import { Input } from '../../input/Input';
+import { Select } from '../../select/Select';
+import { Textarea } from '../../textarea/Textarea';
import { FormLayout } from '../FormLayout';
import '@testing-library/jest-dom/vitest';
@@ -43,8 +47,6 @@ describe('FormLayout', () => {
expect(screen.getByText('Description')).toBeInTheDocument();
expect(screen.getByText('Invalid value')).toBeInTheDocument();
expect(container.querySelector('[data-u-comp="input"]')).toBeInTheDocument();
-
- expect(container.innerHTML).toContain('univer-border-red-500');
});
it('should keep content visible when not collapsable', () => {
@@ -57,4 +59,27 @@ describe('FormLayout', () => {
fireEvent.click(screen.getByText('Always Visible'));
expect(screen.getByText('Child Content')).toBeInTheDocument();
});
+
+ it('propagates validation to the editable controls and clears it when corrected', () => {
+ const fields = (
+ <>
+ <Input aria-label="Name" />
+ <InputNumber aria-label="Count" />
+ <Textarea aria-label="Description" />
+ <Select aria-label="Type" value="first" options={[{ value: 'first', label: 'First' }]} onChange={() => {}} />
+ <FormLayout><Input aria-label="Independent field" /></FormLayout>
+ </>
+ );
+ const { rerender } = render(<FormLayout error="Invalid value">{fields}</FormLayout>);
+ for (const name of ['Name', 'Count', 'Description', 'Type']) {
+ expect(screen.getByLabelText(name)).toHaveAttribute('aria-invalid', 'true');
+ }
+ expect(screen.getByLabelText('Independent field')).not.toHaveAttribute('aria-invalid');
+
+ rerender(<FormLayout>{fields}</FormLayout>);
+ for (const name of ['Name', 'Count', 'Description', 'Type']) {
+ expect(screen.getByLabelText(name)).not.toHaveAttribute('aria-invalid');
+ }
+ expect(screen.queryByText('Invalid value')).not.toBeInTheDocument();
+ });
});
diff --git a/packages/design/src/components/gradient-color-picker/GradientColorPicker.tsx b/packages/design/src/components/gradient-color-picker/GradientColorPicker.tsx
index 2087bd63f4..e3a8d3ee36 100644
--- a/packages/design/src/components/gradient-color-picker/GradientColorPicker.tsx
+++ b/packages/design/src/components/gradient-color-picker/GradientColorPicker.tsx
@@ -240,7 +240,7 @@ export function GradientColorPicker(props: IGradientColorPickerProps) {
: `
univer-flex univer-w-full univer-min-w-0 univer-max-w-80 univer-flex-col univer-gap-4
univer-rounded-lg univer-bg-gray-0 univer-p-4 univer-shadow-lg
- dark:!univer-bg-gray-800
+ dark:!univer-bg-gray-700
`,
className
)}
@@ -282,6 +282,7 @@ export function GradientColorPicker(props: IGradientColorPickerProps) {
: `
univer-text-gray-500
hover:univer-text-gray-900
+ dark:!univer-text-gray-300
dark:hover:!univer-text-gray-0
`
)}
@@ -321,7 +322,14 @@ export function GradientColorPicker(props: IGradientColorPickerProps) {
data-u-comp="gradient-color-picker-angle"
className="univer-flex univer-items-center univer-justify-between univer-gap-3"
>
- <span className="univer-text-xs univer-text-gray-500">{locale?.GradientColorPicker.angle}</span>
+ <span
+ className="
+ univer-text-xs univer-text-gray-500
+ dark:!univer-text-gray-300
+ "
+ >
+ {locale?.GradientColorPicker.angle}
+ </span>
<InputNumber
className="univer-w-24"
value={getGradientAngle(draftValue)}
@@ -412,7 +420,14 @@ export function GradientColorPicker(props: IGradientColorPickerProps) {
<div className="univer-flex univer-items-end univer-gap-2">
<div className="univer-flex-1">
- <div className="univer-mb-0.5 univer-text-xs univer-text-gray-500">{locale?.GradientColorPicker.offset}</div>
+ <div
+ className="
+ univer-mb-0.5 univer-text-xs univer-text-gray-500
+ dark:!univer-text-gray-300
+ "
+ >
+ {locale?.GradientColorPicker.offset}
+ </div>
<InputNumber
value={draftValue.stops[selectedIndex]?.offset}
min={0}
@@ -421,7 +436,12 @@ export function GradientColorPicker(props: IGradientColorPickerProps) {
/>
</div>
<div className="univer-flex-1">
- <div className="univer-mb-0.5 univer-text-xs univer-text-gray-500">
+ <div
+ className="
+ univer-mb-0.5 univer-text-xs univer-text-gray-500
+ dark:!univer-text-gray-300
+ "
+ >
{locale?.GradientColorPicker.transparency}
</div>
<InputNumber
diff --git a/packages/design/src/components/gradient-color-picker/MobileGradientColorPicker.tsx b/packages/design/src/components/gradient-color-picker/MobileGradientColorPicker.tsx
index 6f95ee11ee..a22982cfc3 100644
--- a/packages/design/src/components/gradient-color-picker/MobileGradientColorPicker.tsx
+++ b/packages/design/src/components/gradient-color-picker/MobileGradientColorPicker.tsx
@@ -14,9 +14,10 @@
* limitations under the License.
*/
-import type { GradientType, IGradientColorPickerProps, IGradientStop } from './GradientColorPicker';
import { DeleteIcon, IncreaseIcon } from '@univerjs/icons';
import { useContext, useState } from 'react';
+import type { GradientType, IGradientColorPickerProps, IGradientStop } from './GradientColorPicker';
+import { focusClassName } from '../../helper/class-utilities';
import { clsx } from '../../helper/clsx';
import { Button } from '../button/Button';
import { MobileColorPicker } from '../color-picker/MobileColorPicker';
@@ -53,7 +54,6 @@ export function MobileGradientColorPicker({ value = { type: 'linear', stops: [{
key={type}
title={locale?.GradientColorPicker[type]}
aria-pressed={value.type === type}
- className={value.type === type ? '!univer-bg-primary-50 !univer-text-primary-600' : undefined}
onClick={() => onChange?.({ ...value, type })}
/>
))}
@@ -72,13 +72,19 @@ export function MobileGradientColorPicker({ value = { type: 'linear', stops: [{
type="button"
aria-label={`${locale?.GradientColorPicker.offset} ${stop.offset}%`}
aria-pressed={index === stopIndex}
- className={clsx(`
+ className={clsx(focusClassName, `
univer-flex univer-h-12 univer-min-w-12 univer-appearance-none univer-items-center
univer-justify-center univer-gap-2 univer-rounded-lg univer-border univer-border-solid
univer-bg-transparent univer-px-2 univer-text-sm
`, index === stopIndex
- ? 'univer-border-primary-600 univer-text-primary-600'
- : 'univer-border-gray-200')}
+ ? `
+ univer-border-primary-600 univer-text-primary-600
+ dark:!univer-border-primary-300 dark:!univer-text-primary-300
+ `
+ : `
+ univer-border-gray-200 univer-text-gray-700
+ dark:!univer-border-gray-600 dark:!univer-text-gray-300
+ `)}
onClick={() => setSelectedIndex(stopIndex)}
>
<span className="univer-size-6 univer-shrink-0 univer-rounded" style={{ backgroundColor: stop.color, opacity: stop.opacity ?? 1 }} />
diff --git a/packages/design/src/components/hover-card/HoverCardPrimitive.tsx b/packages/design/src/components/hover-card/HoverCardPrimitive.tsx
index f7c75942a6..047df50e72 100644
--- a/packages/design/src/components/hover-card/HoverCardPrimitive.tsx
+++ b/packages/design/src/components/hover-card/HoverCardPrimitive.tsx
@@ -45,7 +45,7 @@ const HoverCardContent = forwardRef<
data-[side=top]:univer-slide-in-from-bottom-2
univer-z-[1080] univer-w-64 univer-origin-[--radix-hover-card-content-transform-origin] univer-rounded-md
univer-bg-gray-0 univer-text-gray-900 univer-shadow-md univer-outline-none
- dark:!univer-bg-gray-900 dark:!univer-text-gray-0
+ dark:!univer-bg-gray-700 dark:!univer-text-gray-0
`,
borderClassName,
className
diff --git a/packages/design/src/components/input-number/InputNumber.tsx b/packages/design/src/components/input-number/InputNumber.tsx
index 1c45f5c16e..fbeacc1ded 100644
--- a/packages/design/src/components/input-number/InputNumber.tsx
+++ b/packages/design/src/components/input-number/InputNumber.tsx
@@ -32,6 +32,7 @@ export interface IInputNumberProps
precision?: number;
formatter?: (value: string | number | undefined) => string;
parser?: (displayValue: string | undefined) => string;
+ /** Hidden by default in touch density unless an explicit size is supplied. */
controls?: boolean;
className?: string;
inputClassName?: string;
@@ -48,14 +49,14 @@ export const InputNumber = forwardRef<HTMLInputElement, IInputNumberProps>(
{
value,
defaultValue,
- size = 'small',
+ size,
min = Number.MIN_SAFE_INTEGER,
max = Number.MAX_SAFE_INTEGER,
step = 1,
precision,
formatter,
parser,
- controls = true,
+ controls,
className,
inputClassName,
controlsClassName,
@@ -71,7 +72,8 @@ export const InputNumber = forwardRef<HTMLInputElement, IInputNumberProps>(
},
ref
) => {
- const { locale } = useContext(ConfigContext);
+ const { locale, density } = useContext(ConfigContext);
+ const showControls = controls ?? (density !== 'touch' || Boolean(size));
const [internalValue, setInternalValue] = useState<number | null>(
() => {
if (value !== undefined) {
@@ -341,6 +343,7 @@ export const InputNumber = forwardRef<HTMLInputElement, IInputNumberProps>(
<div className={clsx('univer-inline-block', className)}>
<div className="univer-relative univer-w-full">
<Input
+ inputMode={min < 0 ? 'text' : 'decimal'}
{...inputProps}
ref={mergedRef}
className={clsx('univer-box-border', inputClassName)}
@@ -354,7 +357,7 @@ export const InputNumber = forwardRef<HTMLInputElement, IInputNumberProps>(
onKeyDown={handleKeyDown}
/>
- {controls && (
+ {showControls && (
<div
className={clsx(
`
diff --git a/packages/design/src/components/input/Input.tsx b/packages/design/src/components/input/Input.tsx
index 1c4221c9e3..742cbc9d6c 100644
--- a/packages/design/src/components/input/Input.tsx
+++ b/packages/design/src/components/input/Input.tsx
@@ -19,9 +19,10 @@ import type { InputHTMLAttributes } from 'react';
import { CloseIcon } from '@univerjs/icons';
import { cva } from 'class-variance-authority';
import { forwardRef, useContext, useEffect, useRef, useState } from 'react';
-import { borderClassName } from '../../helper/class-utilities';
+import { borderClassName, inputStateClassName } from '../../helper/class-utilities';
import { clsx } from '../../helper/clsx';
import { ConfigContext } from '../config-provider/ConfigProvider';
+import { FormLayoutContext } from '../form-layout/FormLayout';
type InputProps = InputHTMLAttributes<HTMLInputElement>;
@@ -29,10 +30,9 @@ export const inputVariants = cva(
`
univer-box-border univer-w-full univer-rounded-md univer-bg-gray-0 univer-text-gray-900 univer-transition-colors
univer-duration-200
- placeholder:univer-text-gray-400
- focus:univer-border-primary-600 focus:univer-outline-none focus:univer-ring-2 focus:univer-ring-primary-50
+ placeholder:univer-text-gray-500
dark:!univer-bg-gray-700 dark:!univer-text-gray-0
- dark:focus:!univer-ring-primary-900
+ dark:placeholder:univer-text-gray-300
`,
{
variants: {
@@ -75,7 +75,7 @@ export const Input = forwardRef<HTMLInputElement, IInputProps>(
type = 'text',
placeholder,
value,
- size = 'small',
+ size,
allowClear = false,
disabled = false,
onClick,
@@ -88,7 +88,9 @@ export const Input = forwardRef<HTMLInputElement, IInputProps>(
inputStyle,
...props
}, ref) => {
- const { direction, locale } = useContext(ConfigContext);
+ const { direction, locale, density } = useContext(ConfigContext);
+ const invalid = useContext(FormLayoutContext);
+ const touchSize = !size && density === 'touch';
const handleClear = (e: React.MouseEvent) => {
e.stopPropagation();
@@ -146,8 +148,10 @@ export const Input = forwardRef<HTMLInputElement, IInputProps>(
ref={ref}
type={type}
className={clsx(
- inputVariants({ size }),
+ inputVariants({ size: size ?? (touchSize ? 'large' : 'small') }),
borderClassName,
+ inputStateClassName,
+ touchSize && 'univer-text-base',
disabled && `
univer-cursor-not-allowed univer-bg-gray-50 univer-text-gray-400
dark:!univer-text-gray-500
@@ -166,6 +170,7 @@ export const Input = forwardRef<HTMLInputElement, IInputProps>(
onBlur={onBlur}
style={mergedInputStyle}
{...props}
+ aria-invalid={props['aria-invalid'] ?? (invalid || undefined)}
/>
{hasSlotContent && (
<div
diff --git a/packages/design/src/components/message/Message.tsx b/packages/design/src/components/message/Message.tsx
index 3570eb40ab..df65b0ae25 100644
--- a/packages/design/src/components/message/Message.tsx
+++ b/packages/design/src/components/message/Message.tsx
@@ -17,6 +17,7 @@
import type { ComponentProps, ReactNode } from 'react';
import { ErrorIcon, InfoIcon, LoadingMultiIcon, SuccessIcon, WarningIcon } from '@univerjs/icons';
import { toast, Toaster } from 'sonner';
+import { notificationClassName } from '../../helper/class-utilities';
import { clsx } from '../../helper/clsx';
export enum MessageType {
@@ -40,31 +41,59 @@ export type IMessagerProps = Omit<ComponentProps<typeof Toaster>, 'id' | 'positi
const MESSAGE_TOASTER_ID = 'univer-message-toaster';
const DEFAULT_MESSAGE_DURATION = 3000;
const activeMessageIds = new Set<string>();
-const loadingIcon = <LoadingMultiIcon className="univer-animate-spin univer-text-violet-500" />;
+const loadingIcon = (
+ <LoadingMultiIcon
+ className="
+ univer-animate-spin univer-text-primary-600
+ dark:!univer-text-primary-300
+ "
+ />
+);
let messageCount = 0;
const iconMap: Record<MessageType, ReactNode> = {
- [MessageType.Success]: <SuccessIcon className="univer-text-green-500" />,
+ [MessageType.Success]: (
+ <SuccessIcon
+ className="
+ univer-text-green-600
+ dark:!univer-text-green-400
+ "
+ />
+ ),
[MessageType.Info]: (
<InfoIcon
className={`
- univer-text-sky-500
- dark:!univer-text-sky-400
+ univer-text-primary-600
+ dark:!univer-text-primary-300
`}
/>
),
- [MessageType.Warning]: <WarningIcon className="univer-text-amber-500" />,
- [MessageType.Error]: <ErrorIcon className="univer-text-red-500" />,
+ [MessageType.Warning]: (
+ <WarningIcon
+ className="
+ univer-text-yellow-600
+ dark:!univer-text-yellow-400
+ "
+ />
+ ),
+ [MessageType.Error]: (
+ <ErrorIcon
+ className="
+ univer-text-red-600
+ dark:!univer-text-red-400
+ "
+ />
+ ),
[MessageType.Loading]: loadingIcon,
};
const typeClassMap: Record<MessageType, string> = {
- [MessageType.Success]: '[&_[data-icon]]:univer-text-green-500',
- [MessageType.Info]: '[&_[data-icon]]:univer-text-sky-500',
- [MessageType.Warning]: '[&_[data-icon]]:univer-text-amber-500',
- [MessageType.Error]: '[&_[data-icon]]:univer-text-red-500',
- [MessageType.Loading]: '[&_[data-icon]]:univer-text-violet-500',
+ [MessageType.Success]: '[&_[data-icon]]:univer-text-green-600 dark:[&_[data-icon]]:!univer-text-green-400',
+ [MessageType.Info]: '[&_[data-icon]]:univer-text-primary-600 dark:[&_[data-icon]]:!univer-text-primary-300',
+ [MessageType.Warning]: '[&_[data-icon]]:univer-text-yellow-600 dark:[&_[data-icon]]:!univer-text-yellow-400',
+ [MessageType.Error]: '[&_[data-icon]]:univer-text-red-600 dark:[&_[data-icon]]:!univer-text-red-400',
+ [MessageType.Loading]: '[&_[data-icon]]:univer-text-primary-600 dark:[&_[data-icon]]:!univer-text-primary-300',
};
const resolveToastMethod = (type: MessageType) => {
@@ -98,22 +127,12 @@ export const Messager = ({ className, ...props }: IMessagerProps) => (
expand={false}
icons={{ loading: loadingIcon }}
offset={{ top: 16 }}
- className={clsx(
- `
- [&_[data-sonner-toast]]:univer-rounded-2xl [&_[data-sonner-toast]]:univer-border
- [&_[data-sonner-toast]]:univer-border-solid [&_[data-sonner-toast]]:univer-border-gray-200
- [&_[data-sonner-toast]]:univer-bg-gray-0
- [&_[data-sonner-toast]]:univer-shadow-[0_16px_40px_-20px_rgba(15,23,42,0.55)]
- [&_[data-sonner-toast]]:univer-backdrop-blur-sm
- dark:[&_[data-sonner-toast]]:!univer-border-gray-600 dark:[&_[data-sonner-toast]]:!univer-bg-gray-800
- `,
- className
- )}
+ className={clsx(notificationClassName, className)}
toastOptions={{
duration: DEFAULT_MESSAGE_DURATION,
classNames: {
toast: `
- univer-group univer-min-h-0 univer-min-w-[320px] univer-max-w-[520px] univer-px-3.5 univer-py-3
+ univer-group univer-min-h-0 univer-min-w-0 univer-max-w-[520px] univer-px-3.5 univer-py-3
univer-font-sans univer-transition-all univer-duration-300
`,
title: `
diff --git a/packages/design/src/components/mobile-action-row/MobileActionRow.tsx b/packages/design/src/components/mobile-action-row/MobileActionRow.tsx
index d276357490..eb62c97117 100644
--- a/packages/design/src/components/mobile-action-row/MobileActionRow.tsx
+++ b/packages/design/src/components/mobile-action-row/MobileActionRow.tsx
@@ -15,7 +15,7 @@
*/
import type { ButtonHTMLAttributes, ReactNode } from 'react';
-import { borderBottomClassName, resetButtonClassName } from '../../helper/class-utilities';
+import { borderBottomClassName, focusClassName, resetButtonClassName } from '../../helper/class-utilities';
import { clsx } from '../../helper/clsx';
export interface IMobileActionRowProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'title' | 'value'> {
@@ -45,11 +45,13 @@ export function MobileActionRow(props: IMobileActionRowProps) {
return (
<button
type={type}
- className={clsx(resetButtonClassName, `
+ className={clsx(resetButtonClassName, focusClassName, `
univer-flex univer-min-h-12 univer-w-full univer-items-center univer-gap-3 univer-rounded-xl univer-px-4
univer-text-left univer-text-base univer-font-medium univer-text-gray-900
+ aria-pressed:!univer-bg-primary-50 aria-pressed:!univer-text-primary-600
disabled:univer-opacity-40
dark:!univer-text-gray-100
+ dark:aria-pressed:!univer-bg-primary-900 dark:aria-pressed:!univer-text-primary-100
[&>svg]:univer-size-5
`, {
'univer-bg-gray-0 active:univer-bg-gray-100 dark:!univer-bg-gray-800 dark:active:!univer-bg-gray-700': variant === 'surface',
@@ -72,7 +74,7 @@ export function MobileActionRow(props: IMobileActionRowProps) {
<span
className="
univer-max-w-32 univer-truncate univer-text-sm univer-font-normal univer-text-gray-500
- dark:!univer-text-gray-400
+ dark:!univer-text-gray-300
"
>
{value}
diff --git a/packages/design/src/components/radio/Radio.tsx b/packages/design/src/components/radio/Radio.tsx
index 17d6d7fed0..0713cee201 100644
--- a/packages/design/src/components/radio/Radio.tsx
+++ b/packages/design/src/components/radio/Radio.tsx
@@ -80,7 +80,7 @@ export function Radio(props: IRadioProps) {
<span className="univer-relative univer-block">
<input
ref={inputRef}
- className="univer-absolute univer-size-0 univer-opacity-0"
+ className="univer-peer univer-sr-only"
type="radio"
name={name}
checked={checked}
@@ -92,6 +92,9 @@ export function Radio(props: IRadioProps) {
univer-relative univer-box-border univer-flex univer-size-4 univer-items-center
univer-justify-center univer-overflow-hidden univer-rounded-full univer-border univer-border-solid
univer-transition-colors
+ peer-focus:univer-outline peer-focus:univer-outline-2 peer-focus:univer-outline-offset-2
+ peer-focus:univer-outline-primary-600
+ dark:peer-focus:!univer-outline-primary-300
`, {
'univer-opacity-50': disabled,
'univer-border-primary-600 univer-bg-primary-600 dark:!univer-bg-primary-600': checked,
diff --git a/packages/design/src/components/segmented/Segmented.tsx b/packages/design/src/components/segmented/Segmented.tsx
index 83357cf7e5..d56cdb442e 100644
--- a/packages/design/src/components/segmented/Segmented.tsx
+++ b/packages/design/src/components/segmented/Segmented.tsx
@@ -98,7 +98,7 @@ export function Segmented<T extends ItemValue = ItemValue>({
univer-font-medium univer-transition-colors
`, {
'univer-text-gray-900 dark:!univer-text-gray-0': selectedItem === item.value,
- 'univer-text-gray-500 hover:univer-text-gray-900 dark:hover:!univer-text-gray-0': selectedItem !== item.value,
+ 'univer-text-gray-500 hover:univer-text-gray-900 dark:!univer-text-gray-300 dark:hover:!univer-text-gray-0': selectedItem !== item.value,
})}
type="button"
onClick={() => handleClick(item.value)}
diff --git a/packages/design/src/components/select/MobileSelect.tsx b/packages/design/src/components/select/MobileSelect.tsx
index 04fb799bf8..acefcfdadc 100644
--- a/packages/design/src/components/select/MobileSelect.tsx
+++ b/packages/design/src/components/select/MobileSelect.tsx
@@ -15,12 +15,13 @@
*/
import type { ReactNode } from 'react';
+import { MoreDownIcon } from '@univerjs/icons';
+import { useContext, useMemo, useState } from 'react';
import type { IMobileDropdownMenuProps } from '../dropdown-menu/MobileDropdownMenu';
import type { ISelectProps } from './Select';
-import { MoreDownIcon } from '@univerjs/icons';
-import { useMemo, useState } from 'react';
import { clsx } from '../../helper/clsx';
import { MobileDropdownMenu } from '../dropdown-menu/MobileDropdownMenu';
+import { FormLayoutContext } from '../form-layout/FormLayout';
import { selectClassName } from './Select';
interface IOptionSeparator {
@@ -44,6 +45,7 @@ export function MobileSelect(props: IMobileSelectProps) {
...triggerProps
} = props;
const [open, setOpen] = useState(false);
+ const invalid = useContext(FormLayoutContext);
const items: IMobileDropdownMenuProps['items'] = useMemo(() => {
const selectOptions: Array<IOptionSeparator | { label?: ReactNode; value: string; disabled?: boolean }> = [];
@@ -104,10 +106,11 @@ export function MobileSelect(props: IMobileSelectProps) {
disabled={disabled}
aria-expanded={open}
data-u-comp="mobile-select"
+ aria-invalid={triggerProps['aria-invalid'] ?? (invalid || undefined)}
className={clsx(selectClassName, '!univer-h-auto !univer-min-h-12 univer-text-left', {
- 'univer-border-primary-600 univer-outline-none univer-ring-2 univer-ring-primary-50 dark:!univer-ring-primary-900': open && !borderless,
+ '!univer-border-primary-600 univer-outline-none univer-ring-2 univer-ring-primary-50 dark:!univer-border-primary-300 dark:!univer-ring-primary-900': open && !borderless,
'univer-border-transparent univer-bg-transparent': borderless,
- 'univer-cursor-not-allowed': disabled,
+ 'univer-cursor-not-allowed univer-opacity-50': disabled,
'univer-cursor-pointer': !disabled,
}, className)}
>
diff --git a/packages/design/src/components/select/MultipleSelect.tsx b/packages/design/src/components/select/MultipleSelect.tsx
index 992a06e8c8..b084fd7269 100644
--- a/packages/design/src/components/select/MultipleSelect.tsx
+++ b/packages/design/src/components/select/MultipleSelect.tsx
@@ -15,12 +15,13 @@
*/
import type { ReactNode } from 'react';
-import type { IDropdownMenuProps } from '../dropdown-menu/DropdownMenu';
import { MoreDownIcon } from '@univerjs/icons';
-import { useMemo, useState } from 'react';
+import { useContext, useMemo, useState } from 'react';
+import type { IDropdownMenuProps } from '../dropdown-menu/DropdownMenu';
import { clsx } from '../../helper/clsx';
import { Badge } from '../badge/Badge';
import { DropdownMenu } from '../dropdown-menu/DropdownMenu';
+import { FormLayoutContext } from '../form-layout/FormLayout';
import { selectClassName } from './Select';
interface IOption {
@@ -72,6 +73,7 @@ export function MultipleSelect(props: IMultipleSelectProps) {
} = props;
const [open, setOpen] = useState(false);
+ const invalid = useContext(FormLayoutContext);
function handleOpenChange(open: boolean) {
setOpen(open);
@@ -95,24 +97,23 @@ export function MultipleSelect(props: IMultipleSelectProps) {
}, [onChange, options, value]);
function handleClose(item: string) {
+ if (disabled) return;
const newValue = value.filter((v) => v !== item);
onChange(newValue);
}
- const displayValue = useMemo(() => {
- return options
- .filter((option) => value.includes(option.value!))
- .map((option, index) => (
- <Badge
- key={index}
- className="univer-max-w-32"
- closable
- onClose={() => handleClose(option.value!)}
- >
- {option.label}
- </Badge>
- ));
- }, [options, value]);
+ const displayValue = options
+ .filter((option) => value.includes(option.value!))
+ .map((option) => (
+ <Badge
+ key={option.value}
+ className="univer-max-w-32"
+ closable={!disabled && !option.disabled}
+ onClose={() => handleClose(option.value!)}
+ >
+ {option.label}
+ </Badge>
+ ));
return (
<DropdownMenu
@@ -125,10 +126,11 @@ export function MultipleSelect(props: IMultipleSelectProps) {
>
<div
data-u-comp="multiple-select"
+ aria-invalid={invalid || undefined}
className={clsx(selectClassName, {
- 'univer-border-primary-600 univer-outline-none univer-ring-2 univer-ring-primary-50 dark:!univer-ring-primary-900': open && !borderless,
+ '!univer-border-primary-600 univer-outline-none univer-ring-2 univer-ring-primary-50 dark:!univer-border-primary-300 dark:!univer-ring-primary-900': open && !borderless,
'univer-border-transparent univer-bg-transparent hover:univer-border-transparent': borderless,
- 'univer-cursor-not-allowed': disabled,
+ 'univer-cursor-not-allowed univer-opacity-50': disabled,
'hover:univer-border-primary-600': !disabled && !borderless,
'univer-cursor-pointer': !disabled && !open,
}, className)}
diff --git a/packages/design/src/components/select/Select.tsx b/packages/design/src/components/select/Select.tsx
index 39d88f3c64..7e493093c6 100644
--- a/packages/design/src/components/select/Select.tsx
+++ b/packages/design/src/components/select/Select.tsx
@@ -15,13 +15,14 @@
*/
import type { ButtonHTMLAttributes, ReactNode } from 'react';
-import type { IDropdownMenuProps } from '../dropdown-menu/DropdownMenu';
import { MoreDownIcon } from '@univerjs/icons';
-import { useMemo, useState } from 'react';
-import { borderClassName } from '../../helper/class-utilities';
+import { useContext, useMemo, useState } from 'react';
+import type { IDropdownMenuProps } from '../dropdown-menu/DropdownMenu';
+import { borderClassName, focusClassName, inputStateClassName } from '../../helper/class-utilities';
import { clsx } from '../../helper/clsx';
import { Button } from '../button/Button';
import { DropdownMenu } from '../dropdown-menu/DropdownMenu';
+import { FormLayoutContext } from '../form-layout/FormLayout';
interface IOption {
label?: string | ReactNode;
@@ -74,9 +75,9 @@ export interface ISelectProps extends Omit<ButtonHTMLAttributes<HTMLButtonElemen
export const selectClassName = clsx(`
univer-box-border univer-inline-flex univer-h-8 univer-min-w-36 univer-items-center univer-justify-between
- univer-gap-2 univer-rounded-lg univer-bg-gray-0 univer-px-2.5 univer-transition-colors univer-duration-200
+ univer-gap-2 univer-rounded-md univer-bg-gray-0 univer-px-2.5 univer-transition-colors univer-duration-200
dark:!univer-bg-gray-700 dark:!univer-text-gray-0
-`, borderClassName);
+`, borderClassName, focusClassName, inputStateClassName);
const EMPTY_OPTIONS: NonNullable<ISelectProps['options']> = [];
@@ -94,6 +95,7 @@ export function Select(props: ISelectProps) {
} = props;
const [open, setOpen] = useState(false);
+ const invalid = useContext(FormLayoutContext);
function handleOpenChange(open: boolean) {
setOpen(open);
@@ -126,7 +128,6 @@ export function Select(props: ISelectProps) {
return [{
type: 'radio',
value,
- hideIndicator: true,
options: selectOptions,
onSelect: (item) => {
onChange(item);
@@ -172,8 +173,9 @@ export function Select(props: ISelectProps) {
type="button"
disabled={disabled}
data-u-comp="select"
+ aria-invalid={triggerProps['aria-invalid'] ?? (invalid || undefined)}
className={clsx(selectClassName, {
- 'univer-border-primary-600 univer-outline-none univer-ring-2 univer-ring-primary-50 dark:!univer-ring-primary-900': open && !borderless,
+ '!univer-border-primary-600 univer-outline-none univer-ring-2 univer-ring-primary-50 dark:!univer-border-primary-300 dark:!univer-ring-primary-900': open && !borderless,
'univer-border-transparent univer-bg-transparent hover:univer-border-transparent': borderless,
'univer-cursor-not-allowed': disabled,
'hover:univer-border-primary-600': !disabled && !borderless,
diff --git a/packages/design/src/components/select/__tests__/MultipleSelect.spec.tsx b/packages/design/src/components/select/__tests__/MultipleSelect.spec.tsx
index 90852559b7..16ff0cee2f 100644
--- a/packages/design/src/components/select/__tests__/MultipleSelect.spec.tsx
+++ b/packages/design/src/components/select/__tests__/MultipleSelect.spec.tsx
@@ -61,4 +61,22 @@ describe('MultipleSelect', () => {
fireEvent.keyDown(container.querySelector('[data-u-comp="multiple-select"]')!, { key: 'ArrowDown' });
expect(screen.queryByRole('menu')).toBeNull();
});
+
+ it('removes badge close actions when disabled after being enabled', () => {
+ const onChange = vi.fn();
+ const { rerender } = render(
+ <ConfigProvider locale={enUS.design} mountContainer={document.body}>
+ <MultipleSelect value={['first']} options={options} onChange={onChange} />
+ </ConfigProvider>
+ );
+ expect(screen.getByLabelText(enUS.design.Accessibility.closeBadge)).toBeTruthy();
+ rerender(
+ <ConfigProvider locale={enUS.design} mountContainer={document.body}>
+ <MultipleSelect value={['first']} options={options} onChange={onChange} disabled />
+ </ConfigProvider>
+ );
+ expect(screen.queryByLabelText(enUS.design.Accessibility.closeBadge)).toBeNull();
+ fireEvent.click(screen.getByText('First'));
+ expect(onChange).not.toHaveBeenCalled();
+ });
});
diff --git a/packages/design/src/components/textarea/Textarea.tsx b/packages/design/src/components/textarea/Textarea.tsx
index 99fd88e011..9f48c0aa42 100644
--- a/packages/design/src/components/textarea/Textarea.tsx
+++ b/packages/design/src/components/textarea/Textarea.tsx
@@ -15,9 +15,11 @@
*/
import type { ChangeEvent, ComponentProps } from 'react';
-import { forwardRef, useImperativeHandle, useLayoutEffect, useRef } from 'react';
-import { borderClassName, scrollbarClassName } from '../../helper/class-utilities';
+import { forwardRef, useContext, useImperativeHandle, useLayoutEffect, useRef } from 'react';
+import { borderClassName, inputStateClassName, scrollbarClassName } from '../../helper/class-utilities';
import { clsx } from '../../helper/clsx';
+import { ConfigContext } from '../config-provider/ConfigProvider';
+import { FormLayoutContext } from '../form-layout/FormLayout';
interface ITextareaProps extends ComponentProps<'textarea'> {
className?: string;
@@ -30,6 +32,8 @@ export const Textarea = forwardRef<HTMLTextAreaElement, ITextareaProps>((props,
const lastSizeRef = useRef<{ width: number; height: number }>({ width: 0, height: 0 });
const { className, onResize, onValueChange, ...restProps } = props;
+ const invalid = useContext(FormLayoutContext);
+ const { density } = useContext(ConfigContext);
useImperativeHandle(ref, () => textareaRef.current as HTMLTextAreaElement, []);
@@ -71,19 +75,22 @@ export const Textarea = forwardRef<HTMLTextAreaElement, ITextareaProps>((props,
data-slot="textarea"
className={clsx(
`
- univer-box-border univer-flex univer-w-full univer-resize univer-rounded-md univer-bg-transparent
- univer-p-2 univer-text-base univer-text-gray-900 univer-outline-none
- univer-transition-[color,box-shadow]
- placeholder:univer-text-gray-200
+ univer-box-border univer-flex univer-w-full univer-resize univer-rounded-md univer-bg-gray-0
+ univer-p-2 univer-text-sm univer-text-gray-900 univer-transition-[color,box-shadow]
+ placeholder:univer-text-gray-500
disabled:univer-cursor-not-allowed disabled:univer-opacity-50
- dark:!univer-text-gray-0
+ dark:!univer-bg-gray-700 dark:!univer-text-gray-0
+ dark:placeholder:univer-text-gray-300
`,
borderClassName,
+ inputStateClassName,
+ density === 'touch' && 'univer-text-base',
scrollbarClassName,
className
)}
onChange={handleChange}
{...restProps}
+ aria-invalid={restProps['aria-invalid'] ?? (invalid || undefined)}
/>
);
});
diff --git a/packages/design/src/components/time-input/TimeInput.tsx b/packages/design/src/components/time-input/TimeInput.tsx
index 2fe8dc3d7c..2a89a60a3d 100644
--- a/packages/design/src/components/time-input/TimeInput.tsx
+++ b/packages/design/src/components/time-input/TimeInput.tsx
@@ -16,7 +16,7 @@
import type { ChangeEvent } from 'react';
import { ClockIcon } from '@univerjs/icons';
-import { borderClassName } from '../../helper/class-utilities';
+import { borderClassName, inputStateClassName } from '../../helper/class-utilities';
import { clsx } from '../../helper/clsx';
import { formatDateWithPattern } from '../../helper/date';
@@ -48,15 +48,13 @@ export function TimeInput(props: ITimeInputProps) {
/>
<input
className={clsx(`
- univer-block univer-h-7 univer-w-fit univer-appearance-none univer-rounded-md univer-bg-transparent
- univer-pl-6 univer-pr-2 univer-text-center univer-text-gray-800 univer-shadow univer-outline-none
+ univer-box-border univer-block univer-h-7 univer-w-fit univer-appearance-none univer-rounded-md
+ univer-bg-gray-0 univer-pl-6 univer-pr-2 univer-text-center univer-text-sm univer-text-gray-800
univer-transition-all univer-duration-200
- focus:univer-border-primary-600
- dark:!univer-text-gray-0
- dark:focus:!univer-border-primary-500
+ dark:!univer-bg-gray-700 dark:!univer-text-gray-0
[&::-webkit-calendar-picker-indicator]:univer-hidden
[&::-webkit-calendar-picker-indicator]:univer-appearance-none
- `, borderClassName, className)}
+ `, borderClassName, inputStateClassName, className)}
type="time"
step="1"
value={formatDateWithPattern(value, 'HH:mm:ss')}
diff --git a/packages/design/src/components/toaster/Toaster.tsx b/packages/design/src/components/toaster/Toaster.tsx
index 7bb03d152f..36d2a2e9cf 100644
--- a/packages/design/src/components/toaster/Toaster.tsx
+++ b/packages/design/src/components/toaster/Toaster.tsx
@@ -16,27 +16,25 @@
import type { ComponentProps } from 'react';
import { Toaster as Sonner, toast } from 'sonner';
+import { notificationClassName } from '../../helper/class-utilities';
+import { clsx } from '../../helper/clsx';
export type IToasterProps = ComponentProps<typeof Sonner>;
function Toaster({ visibleToasts, ...props }: IToasterProps) {
return (
<Sonner
- className={`
- [&_[data-description]]:univer-text-sm [&_[data-description]]:univer-text-gray-600
- dark:[&_[data-description]]:!univer-text-gray-200
+ className={clsx(notificationClassName, `
[&_[data-icon]>svg]:univer-relative [&_[data-icon]>svg]:univer-top-1
[&_[data-icon]]:univer-self-baseline
- [&_[data-sonner-toast]]:univer-shadow-md
- [&_[data-title]]:univer-text-sm [&_[data-title]]:univer-text-gray-900
- `}
+ `)}
toastOptions={{
classNames: {
content: 'univer-leading-normal',
- success: '[&_[data-icon]]:univer-text-green-500',
- info: '[&_[data-icon]]:univer-text-primary-600',
- error: '[&_[data-icon]]:univer-text-red-500',
- warning: '[&_[data-icon]]:univer-text-yellow-500',
+ success: '[&_[data-icon]]:univer-text-green-600 dark:[&_[data-icon]]:!univer-text-green-400',
+ info: '[&_[data-icon]]:univer-text-primary-600 dark:[&_[data-icon]]:!univer-text-primary-300',
+ error: '[&_[data-icon]]:univer-text-red-600 dark:[&_[data-icon]]:!univer-text-red-400',
+ warning: '[&_[data-icon]]:univer-text-yellow-600 dark:[&_[data-icon]]:!univer-text-yellow-400',
},
}}
visibleToasts={visibleToasts ?? 5}
diff --git a/packages/design/src/helper/class-utilities.ts b/packages/design/src/helper/class-utilities.ts
index ec67d8a528..5776b12768 100644
--- a/packages/design/src/helper/class-utilities.ts
+++ b/packages/design/src/helper/class-utilities.ts
@@ -29,3 +29,22 @@ export const borderRightClassName = clsx(borderBasicClassName, 'univer-border-l-
export const divideYClassName = 'univer-divide-gray-200 dark:!univer-divide-gray-600 univer-divide-y univer-divide-x-0 univer-divide-solid';
export const divideXClassName = 'univer-divide-gray-200 dark:!univer-divide-gray-600 univer-divide-x univer-divide-y-0 univer-divide-solid';
export const resetButtonClassName = 'univer-m-0 univer-flex univer-appearance-none univer-items-center univer-justify-center univer-border-0 univer-bg-transparent univer-p-0 univer-leading-none univer-outline-none univer-cursor-pointer';
+
+export const focusClassName = 'focus:univer-outline focus:univer-outline-2 focus:univer-outline-offset-2 focus:univer-outline-primary-600 dark:focus:!univer-outline-primary-300';
+
+export const inputStateClassName = `
+ focus:!univer-border-primary-600 focus:univer-outline-none focus:univer-ring-2 focus:univer-ring-primary-50
+ dark:focus:!univer-border-primary-300 dark:focus:!univer-ring-primary-900
+ aria-[invalid=true]:!univer-border-red-600 aria-[invalid=true]:focus:!univer-border-red-600 aria-[invalid=true]:focus:univer-ring-red-50
+ dark:aria-[invalid=true]:!univer-border-red-400 dark:aria-[invalid=true]:focus:!univer-border-red-400 dark:aria-[invalid=true]:focus:!univer-ring-red-900
+`;
+
+export const notificationClassName = `
+ [&_[data-sonner-toast]]:!univer-rounded-lg [&_[data-sonner-toast]]:!univer-border-gray-200
+ [&_[data-sonner-toast]]:!univer-bg-gray-0 [&_[data-sonner-toast]]:!univer-shadow-md
+ dark:[&_[data-sonner-toast]]:!univer-border-gray-600 dark:[&_[data-sonner-toast]]:!univer-bg-gray-700
+ [&_[data-title]]:!univer-text-sm [&_[data-title]]:!univer-text-gray-900
+ dark:[&_[data-title]]:!univer-text-gray-0
+ [&_[data-description]]:!univer-text-sm [&_[data-description]]:!univer-text-gray-600
+ dark:[&_[data-description]]:!univer-text-gray-200
+`;
diff --git a/packages/ui/src/views/mobile-workbench/MobileWorkbench.tsx b/packages/ui/src/views/mobile-workbench/MobileWorkbench.tsx
index 2512d39bb6..fd98f4ca69 100644
--- a/packages/ui/src/views/mobile-workbench/MobileWorkbench.tsx
+++ b/packages/ui/src/views/mobile-workbench/MobileWorkbench.tsx
@@ -299,6 +299,7 @@ export function MobileWorkbench(props: IUniverAppProps) {
<ConfigProvider
locale={locale?.design}
direction={direction}
+ density="touch"
mountContainer={portalContainer}
mobileKeyboardViewport={keyboardViewport}
>