收口编辑器图标按钮组件
EditorIconButton 改为委托 PlatformIconButton,保留编辑器本地样式入口。 新增编辑器按钮 primitive 测试,覆盖可访问属性和平台图标按钮 chrome。 更新 TRACKING 记录本次组件复用收口。
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
/* @vitest-environment jsdom */
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { Check } from 'lucide-react';
|
||||
import { expect, test } from 'vitest';
|
||||
|
||||
import { EditorIconButton } from './ImageCanvasEditorPrimitives';
|
||||
|
||||
test('editor icon button delegates accessible icon chrome to the platform primitive', () => {
|
||||
render(
|
||||
<EditorIconButton
|
||||
label="素材选择模式"
|
||||
title="选择"
|
||||
icon={Check}
|
||||
className="image-canvas-editor__icon-button"
|
||||
pressed
|
||||
expanded
|
||||
/>,
|
||||
);
|
||||
|
||||
const button = screen.getByRole('button', { name: '素材选择模式' });
|
||||
|
||||
expect(button.className).toContain('platform-icon-button');
|
||||
expect(button.className).toContain('image-canvas-editor__icon-button');
|
||||
expect(button.getAttribute('title')).toBe('选择');
|
||||
expect(button.getAttribute('aria-pressed')).toBe('true');
|
||||
expect(button.getAttribute('aria-expanded')).toBe('true');
|
||||
});
|
||||
@@ -5,6 +5,8 @@ import type {
|
||||
ReactNode,
|
||||
} from 'react';
|
||||
|
||||
import { PlatformIconButton } from '../common/PlatformIconButton';
|
||||
|
||||
type IconComponent = ComponentType<{ className?: string }>;
|
||||
|
||||
export type EditorIconButtonProps = {
|
||||
@@ -31,18 +33,17 @@ export function EditorIconButton({
|
||||
onClick,
|
||||
}: EditorIconButtonProps) {
|
||||
return (
|
||||
<button
|
||||
<PlatformIconButton
|
||||
type={type}
|
||||
className={className}
|
||||
aria-label={label}
|
||||
label={label}
|
||||
title={title}
|
||||
disabled={disabled}
|
||||
aria-pressed={pressed}
|
||||
aria-expanded={expanded}
|
||||
onClick={onClick}
|
||||
>
|
||||
<Icon className="h-4 w-4" />
|
||||
</button>
|
||||
icon={<Icon className="h-4 w-4" />}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user