fix(web): expose names for base controls

This commit is contained in:
yyh
2026-05-10 21:54:40 +08:00
parent 839870d38d
commit 07cd3daa5d
6 changed files with 9 additions and 8 deletions

View File

@ -90,7 +90,7 @@ describe('FloatRightContainer', () => {
)
await screen.findByRole('dialog')
const closeIcon = screen.getByTestId('close-icon')
const closeIcon = screen.getByRole('button', { name: 'common.operation.close' })
expect(closeIcon).toBeInTheDocument()
await userEvent.click(closeIcon)

View File

@ -63,7 +63,6 @@ const FloatRightContainer = ({
<DrawerCloseButton
aria-label={t('operation.close', { ns: 'common' })}
className="h-6 w-6 rounded-md"
data-testid="close-icon"
/>
)}
</div>

View File

@ -21,7 +21,7 @@ describe('CheckboxField', () => {
it('should toggle on when unchecked users click the checkbox', () => {
mockField.state.value = false
render(<CheckboxField label="Enable feature" />)
fireEvent.click(screen.getByTestId('checkbox-checkbox-field'))
fireEvent.click(screen.getByRole('checkbox', { name: 'Enable feature' }))
expect(mockField.handleChange).toHaveBeenCalledWith(true)
})

View File

@ -19,6 +19,7 @@ const CheckboxField = ({
<Checkbox
id={field.name}
checked={field.state.value}
ariaLabel={label}
onCheck={() => {
field.handleChange(!field.state.value)
}}

View File

@ -66,7 +66,7 @@ describe('Input component', () => {
it('calls onClear when clear icon is clicked', () => {
const onClear = vi.fn()
render(<Input showClearIcon value="test" onClear={onClear} />)
const clearIconContainer = screen.getByTestId('input-clear')
const clearIconContainer = screen.getByRole('button', { name: 'common.operation.clear' })
fireEvent.click(clearIconContainer!)
expect(onClear).toHaveBeenCalledTimes(1)
})

View File

@ -109,13 +109,14 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(({
{...props}
/>
{!!(showClearIcon && value && !disabled && !destructive) && (
<div
<button
type="button"
aria-label={t('operation.clear', { ns: 'common' })}
className={cn('group absolute top-1/2 right-2 -translate-y-1/2 cursor-pointer p-px')}
onClick={onClear}
data-testid="input-clear"
>
<span className="i-ri-close-circle-fill h-3.5 w-3.5 cursor-pointer text-text-quaternary group-hover:text-text-tertiary" />
</div>
<span className="i-ri-close-circle-fill h-3.5 w-3.5 cursor-pointer text-text-quaternary group-hover:text-text-tertiary" aria-hidden="true" />
</button>
)}
{destructive && (
<span className="absolute top-1/2 right-2 i-ri-error-warning-line h-4 w-4 -translate-y-1/2 text-text-destructive-secondary" />