Skip to content

Commit e2d824a

Browse files
authored
fix(select): add some aria-* props for ai (#3875)
* fix(select): add some aria-* props for ai * fix(select): fix select's e2e test
1 parent 241585e commit e2d824a

File tree

11 files changed

+44
-15
lines changed

11 files changed

+44
-15
lines changed

examples/sites/demos/pc/app/select/allow-create.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ test('点击选中', async ({ page }) => {
1616
await input.dispatchEvent('keyup', { KeyboardEvent })
1717

1818
await expect(input).toHaveValue('测试 allow-create')
19-
await dropdown.getByRole('listitem').filter({ hasText: '测试 allow-create' }).click()
19+
await dropdown.locator('.tiny-option').filter({ hasText: '测试 allow-create' }).click()
2020
await expect(input).toHaveValue('测试 allow-create')
2121

2222
await input.click()
2323
await expect(input).toHaveValue('')
24-
await expect(dropdown.getByRole('listitem').filter({ hasText: '测试 allow-create' })).toHaveClass(/selected/)
24+
await expect(dropdown.locator('.tiny-option').filter({ hasText: '测试 allow-create' })).toHaveClass(/selected/)
2525
})
2626

2727
test('enter 选中', async ({ page }) => {
@@ -46,5 +46,5 @@ test('enter 选中', async ({ page }) => {
4646
await input.click()
4747

4848
await expect(input).toHaveValue('')
49-
await expect(dropdown.getByRole('listitem').filter({ hasText: 'ab' })).toHaveClass(/selected/)
49+
await expect(dropdown.locator('.tiny-option').filter({ hasText: 'ab' })).toHaveClass(/selected/)
5050
})

examples/sites/demos/pc/app/select/automatic-dropdown.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ test('可搜索时,获取焦点自动下拉', async ({ page }) => {
2323

2424
await wrap.getByRole('button').nth(1).click()
2525
// 聚焦下拉
26-
await dropdown.getByRole('listitem').filter({ hasText: '上海' }).click()
26+
await dropdown.locator('.tiny-option').filter({ hasText: '上海' }).click()
2727
await expect(input).toHaveValue('上海')
2828
// 验证选中
2929
await input.click()
30-
await expect(page.getByRole('listitem').filter({ hasText: '上海' })).toHaveClass(/selected/)
30+
await expect(dropdown.locator('.tiny-option').filter({ hasText: '上海' })).toHaveClass(/selected/)
3131
})

examples/sites/demos/pc/app/select/basic-usage.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ test('基础用法标签式', async ({ page }) => {
66
const wrap = page.locator('#basic-usage')
77
const select = wrap.locator('.tiny-select').nth(0)
88
const input = select.locator('.tiny-input__inner')
9-
const dropdown = page.locator('body > .tiny-select-dropdown')
9+
const dropdown = page.locator('body > .tiny-select-dropdown').nth(0)
1010
const option = dropdown.locator('.tiny-option')
1111

1212
await input.click()
1313
await option.filter({ hasText: '天津' }).click()
1414
await expect(input).toHaveValue('天津')
1515
await select.locator('.tiny-input__suffix svg').click()
16-
await expect(page.getByRole('listitem').filter({ hasText: '天津' })).toHaveClass(/selected/)
16+
await expect(dropdown.locator('.tiny-option').filter({ hasText: '天津' })).toHaveClass(/selected/)
1717
await option.filter({ hasText: '深圳' }).click()
1818
await expect(input).toHaveValue('深圳')
1919
await input.click()
@@ -36,7 +36,7 @@ test('基础用法配置式', async ({ page }) => {
3636
await option.filter({ hasText: '天津' }).click()
3737
await expect(input).toHaveValue('天津')
3838
await select.locator('.tiny-input__suffix svg').click()
39-
await expect(page.getByRole('listitem').filter({ hasText: '天津' })).toHaveClass(/selected/)
39+
await expect(dropdown.locator('.tiny-option').filter({ hasText: '天津' })).toHaveClass(/selected/)
4040
await option.filter({ hasText: '深圳' }).click()
4141
await expect(input).toHaveValue('深圳')
4242
await input.click()

examples/sites/demos/pc/app/select/binding-obj.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ test('binding-obj', async ({ page }) => {
1010
const valueLocator = wrap.locator('.value')
1111

1212
await input.click()
13-
await dropdown.getByRole('listitem').filter({ hasText: '重庆' }).click()
13+
await dropdown.locator('.tiny-option').filter({ hasText: '重庆' }).click()
1414
await expect(input).toHaveValue('重庆')
1515
await expect(valueLocator).toHaveText('{ "val": "选项 4", "id": 4 }')
1616

1717
await input.click()
18-
await dropdown.getByRole('listitem').filter({ hasText: '天津' }).click()
18+
await dropdown.locator('.tiny-option').filter({ hasText: '天津' }).click()
1919
await expect(input).toHaveValue('天津')
2020
await expect(valueLocator).toHaveText('{ "val": "选项 3", "id": 3 }')
2121
})

examples/sites/demos/pc/app/select/cache-usage.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ test('cache-op', async ({ page }) => {
1010
const cacheValue = wrap.locator('.cache-value')
1111

1212
await input.click()
13-
await dropdown.getByRole('listitem').filter({ hasText: '北京' }).click()
13+
await dropdown.locator('.tiny-option').filter({ hasText: '北京' }).click()
1414
await expect(cacheValue).toContainText(['选项 1'])
1515

1616
await input.click()
17-
await dropdown.getByRole('listitem').filter({ hasText: '上海' }).click()
17+
await dropdown.locator('.tiny-option').filter({ hasText: '上海' }).click()
1818
await expect(cacheValue).toContainText(['选项 2'])
1919
})

examples/sites/demos/pc/app/select/clearable.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ test('clearable', async ({ page }) => {
1616
await expect(input).toHaveValue('')
1717
// 验证选中
1818
await icon.click()
19-
await dropdown.getByRole('listitem').filter({ hasText: '上海' }).click()
19+
await dropdown.locator('.tiny-option').filter({ hasText: '上海' }).click()
2020
await expect(input).toHaveValue('上海')
2121
})

packages/renderless/src/select/vue.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,8 @@ const initState = ({
296296
content: state.displayOnlyContent,
297297
always: !!state.displayOnlyContent,
298298
...props.tooltipConfig
299-
}))
299+
})),
300+
ariaListId: 'tiny-select-' + crypto.randomUUID().slice(-8)
300301
})
301302

302303
return state

packages/vue/src/option/src/mobile-first.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
)
2222
"
2323
data-tag="tiny-option"
24+
role="option"
25+
:aria-label="state.currentLabel"
26+
:aria-selected="state.itemSelected"
2427
>
2528
<span v-if="state.selectMultiple" class="w-4 mr-2">
2629
<component

packages/vue/src/option/src/pc.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
},
1818
highlightClass
1919
]"
20+
role="option"
21+
:aria-label="state.currentLabel"
22+
:aria-selected="state.itemSelected"
2023
>
2124
<span v-if="state.selectMultiple" class="tiny-option__checkbox-wrap tiny-select-dropdown__item-checkbox">
2225
<component :is="`icon-${state.selectCls}`" :class="`tiny-svg-size ${state.selectCls}`" />

packages/vue/src/select/src/mobile-first.vue

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@
245245
'max-width': state.inputWidth - 42 + 'px',
246246
height: 'auto'
247247
}"
248+
role="combobox"
249+
aria-haspopup="listbox"
250+
aria-autocomplete="list"
251+
:aria-owns="state.ariaListId"
252+
:aria-controls="state.ariaListId"
248253
/>
249254
</div>
250255
<tiny-input
@@ -277,6 +282,11 @@
277282
@mouseenter="onMouseenterNative"
278283
@mouseleave="onMouseleaveNative"
279284
@compositionend.native="handleComposition"
285+
role="combobox"
286+
aria-haspopup="listbox"
287+
aria-autocomplete="list"
288+
:aria-owns="state.ariaListId"
289+
:aria-controls="state.ariaListId"
280290
>
281291
<template #prefix v-if="slots.prefix">
282292
<slot name="prefix"></slot>
@@ -340,6 +350,8 @@
340350
:popper-options="popperOptions"
341351
:class="m('duration-300')"
342352
:height="dropdownHeight"
353+
role="listbox"
354+
:id="state.ariaListId"
343355
>
344356
<div
345357
v-if="shape && filterable"
@@ -451,7 +463,10 @@
451463
<component
452464
:is="`icon-${state.selectCls}`"
453465
:class="
454-
m(['-mt-0.5 mr-2 fill-color-icon-secondary w-3.5 h-3.5 ', state.selectCls !== 'check' && 'fill-color-brand text-color-brand'])
466+
m([
467+
'-mt-0.5 mr-2 fill-color-icon-secondary w-3.5 h-3.5 ',
468+
state.selectCls !== 'check' && 'fill-color-brand text-color-brand'
469+
])
455470
"
456471
/>
457472
<span :class="[state.selectCls === 'checked-sur' ? 'text-color-brand' : 'text-color-text-primary']">

0 commit comments

Comments
 (0)