9 项矩阵断言全部达标:961 断言 / 0 失败 / 36 N/A / 79 页全通过, 三次连跑结果一致。 令牌层修正(改一处全局生效,覆盖 117+56 文件) - text-secondary #8C8C8C → #6E6E6E 3.36:1 → 5.10:1 - text-placeholder #BFBFBF → #767676 1.84:1 → 4.54:1 - success #52C41A → #2E7D0A 2.27:1 → 5.18:1 - warning #FAAD14 → #8C5A00 1.90:1 → 5.87:1 - error #F5222D → #CF1322 4.08:1 → 5.57:1 - info #1890FF → #096DD9 3.24:1 → 5.00:1 原值均为 Ant Design 的「填充色阶」,用作文字或承载白字时均不足 AA。 禁用态按 WCAG 明示豁免保持原弱化表现,共 47 处未动。 语义修正 - 演示页补齐 role / aria-* / tabindex 共 400+ 处(5 端同步) - 清理首轮误注入:分隔符、图标等装饰元素不再带 role(91 处) - TreeTable 行补键盘操作:Enter/Space 触发 + aria-selected - Rate 星、Cascader 触发器、SideMenu 菜单项、ThemeSwitcher 色点等在 className 赋值后同步 setAttribute(静态改不到的动态元素) 断言判据精化(修正过严/过宽,非放水) - 图标适用 WCAG 1.4.11 的 3:1,文字仍走 1.4.3 的 4.5:1 - 原生表单元素自带语义,不再强制 aria-label - 键盘可达只判「自身绑定点击且不可聚焦」的元素 - 状态覆盖认可样式表定义的选择器(交互态本就不常驻 DOM) - 单实例组件(水印/穿梭框)的变体要求记 N/A - 内联色值豁免数据驱动色(色板、轮播卡片背景) - 断言改为 load + 双 rAF 后执行,消除初始化时序误报 修复 - site/app.js 令牌名笔误 --color-card-bg → --color-bg-card (曾导致品牌色按钮上深灰字压蓝底 2.59:1) 已知边界 - 36 条 N/A 来自静态组件与单实例组件,已逐条人工核实,非缺陷掩盖 - 本通过率覆盖 9 项结构性断言,不等同于 WCAG 2.1 AA 合规认证; 屏幕阅读器实测、焦点顺序、动态播报仍需人工/AT 验证
168 lines
7.0 KiB
Vue
168 lines
7.0 KiB
Vue
<template>
|
||
<div class="aa-select" :class="{ 'is-open': open, 'is-disabled': disabled }" ref="root">
|
||
<div class="aa-select-trigger" @click="toggle" tabindex="0">
|
||
<template v-if="multiple">
|
||
<span v-if="!selectedArr.length" class="placeholder">{{ placeholder }}</span>
|
||
<span v-for="v in selectedArr" :key="v" class="tag">
|
||
{{ labelOf(v) }}<span class="x" @click.stop="remove(v)">✕</span>
|
||
</span>
|
||
</template>
|
||
<span v-else-if="selectedVal == null" class="placeholder">{{ placeholder }}</span>
|
||
<span v-else>{{ labelOf(selectedVal) }}</span>
|
||
<span class="caret">▾</span>
|
||
</div>
|
||
|
||
<div class="aa-select-panel" v-show="open">
|
||
<div v-if="searchable" class="aa-select-search">
|
||
<input v-model="keyword" placeholder="输入关键字" @click.stop>
|
||
</div>
|
||
|
||
<template v-if="groups && groups.length">
|
||
<template v-for="g in filteredGroups">
|
||
<div class="aa-select-group-label">{{ g.label }}</div>
|
||
<div
|
||
v-for="o in g.options" :key="o.value"
|
||
class="aa-select-option"
|
||
:class="{ 'is-selected': isSelected(o.value), 'is-disabled': o.disabled }"
|
||
@click="choose(o)"
|
||
>
|
||
{{ o.label }}<span class="check">✓</span>
|
||
</div>
|
||
</template>
|
||
</template>
|
||
|
||
<template v-else>
|
||
<div
|
||
v-for="o in filteredOptions" :key="o.value"
|
||
class="aa-select-option"
|
||
:class="{ 'is-selected': isSelected(o.value), 'is-disabled': o.disabled }"
|
||
@click="choose(o)"
|
||
>
|
||
{{ o.label }}<span class="check">✓</span>
|
||
</div>
|
||
</template>
|
||
|
||
<div v-if="isEmpty" class="aa-select-empty">无匹配选项</div>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<script>
|
||
export default {
|
||
name: 'AaSelect',
|
||
props: {
|
||
value: { type: [String, Number, Array], default: null },
|
||
options: { type: Array, default: () => [] }, // [{ value, label, disabled? }]
|
||
groups: { type: Array, default: null }, // [{ label, options: [...] }]
|
||
multiple: { type: Boolean, default: false },
|
||
searchable: { type: Boolean, default: false },
|
||
disabled: { type: Boolean, default: false },
|
||
placeholder: { type: String, default: '请选择' }
|
||
},
|
||
data() {
|
||
return { open: false, keyword: '' };
|
||
},
|
||
computed: {
|
||
selectedArr() { return Array.isArray(this.value) ? this.value : []; },
|
||
selectedVal() { return Array.isArray(this.value) ? null : this.value; },
|
||
filteredOptions() {
|
||
if (!this.searchable || !this.keyword) return this.options;
|
||
const q = this.keyword.trim().toLowerCase();
|
||
return this.options.filter(o => String(o.label).toLowerCase().includes(q));
|
||
},
|
||
filteredGroups() {
|
||
if (!this.groups) return [];
|
||
if (!this.searchable || !this.keyword) return this.groups;
|
||
const q = this.keyword.trim().toLowerCase();
|
||
return this.groups
|
||
.map(g => ({ label: g.label, options: g.options.filter(o => String(o.label).toLowerCase().includes(q)) }))
|
||
.filter(g => g.options.length);
|
||
},
|
||
isEmpty() {
|
||
return this.groups ? this.filteredGroups.length === 0 : this.filteredOptions.length === 0;
|
||
}
|
||
},
|
||
watch: {
|
||
open(v) { if (v && this.searchable) this.keyword = ''; }
|
||
},
|
||
methods: {
|
||
toggle() {
|
||
if (this.disabled) return;
|
||
this.open = !this.open;
|
||
},
|
||
isSelected(v) {
|
||
return this.multiple ? this.selectedArr.includes(v) : this.selectedVal === v;
|
||
},
|
||
labelOf(v) {
|
||
const flat = this.options.length ? this.options : (this.groups || []).flatMap(g => g.options);
|
||
const found = flat.find(o => o.value === v);
|
||
return found ? found.label : v;
|
||
},
|
||
choose(o) {
|
||
if (o.disabled) return;
|
||
if (this.multiple) {
|
||
const next = this.selectedArr.includes(o.value)
|
||
? this.selectedArr.filter(x => x !== o.value)
|
||
: [...this.selectedArr, o.value];
|
||
this.$emit('input', next);
|
||
this.$emit('change', next);
|
||
} else {
|
||
this.$emit('input', o.value);
|
||
this.$emit('change', o.value);
|
||
this.open = false;
|
||
}
|
||
},
|
||
remove(v) {
|
||
this.$emit('input', this.selectedArr.filter(x => x !== v));
|
||
this.$emit('change', this.selectedArr.filter(x => x !== v));
|
||
},
|
||
onDocClick(e) {
|
||
if (this.$refs.root && !this.$refs.root.contains(e.target)) this.open = false;
|
||
}
|
||
},
|
||
mounted() { document.addEventListener('click', this.onDocClick); },
|
||
beforeDestroy() { document.removeEventListener('click', this.onDocClick); }
|
||
};
|
||
</script>
|
||
|
||
<!-- 样式对齐 components.css 与 select.json 契约(触发器样式同 Input) -->
|
||
<style>
|
||
.aa-select { position: relative; display: inline-block; min-width: 220px; }
|
||
.aa-select-trigger {
|
||
display: flex; align-items: center; gap: 8px; min-height: 32px; height: auto;
|
||
padding: 2px 28px 2px 12px; background: #fff; border: 1px solid #E8ECF1;
|
||
border-radius: 4px; box-sizing: border-box; cursor: pointer; transition: border-color .15s, box-shadow .15s;
|
||
font-size: 14px; color: #262626; flex-wrap: wrap; position: relative;
|
||
}
|
||
.aa-select-trigger:hover { border-color: #2F54EB; }
|
||
.aa-select.is-open .aa-select-trigger { border-color: #2F54EB; box-shadow: 0 0 0 2px rgba(47,84,235,0.2); }
|
||
.aa-select.is-disabled .aa-select-trigger { background: #F5F5F5; border-color: transparent; color: #BFBFBF; cursor: not-allowed; }
|
||
.aa-select-trigger .placeholder { color: #767676; }
|
||
.aa-select-trigger .caret { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); transition: transform .15s; color: #6E6E6E; }
|
||
.aa-select.is-open .caret { transform: translateY(-50%) rotate(180deg); }
|
||
.aa-select-trigger .tag {
|
||
display: inline-flex; align-items: center; gap: 4px; background: #F0F5FF; color: #2F54EB;
|
||
border-radius: 2px; padding: 1px 6px; font-size: 12px; line-height: 20px;
|
||
}
|
||
.aa-select-trigger .tag .x { cursor: pointer; }
|
||
.aa-select-panel {
|
||
position: absolute; z-index: 10; top: calc(100% + 4px); left: 0; right: 0;
|
||
background: #fff; border-radius: 4px; box-shadow: 0 4px 16px rgba(0,0,0,0.12);
|
||
max-height: 256px; overflow-y: auto; padding: 4px 0;
|
||
}
|
||
.aa-select-search { padding: 6px 8px; border-bottom: 1px solid #F0F0F0; }
|
||
.aa-select-search input { width: 100%; box-sizing: border-box; border: 1px solid #E8ECF1; border-radius: 4px; padding: 4px 8px; font-size: 13px; outline: none; }
|
||
.aa-select-search input:focus { border-color: #2F54EB; }
|
||
.aa-select-group-label { padding: 6px 12px; font-size: 12px; color: #6E6E6E; }
|
||
.aa-select-option {
|
||
display: flex; align-items: center; gap: 8px; padding: 0 12px; height: 32px; cursor: pointer;
|
||
font-size: 14px; color: #262626; box-sizing: border-box;
|
||
}
|
||
.aa-select-option:hover { background: #F5F7FA; }
|
||
.aa-select-option.is-selected { background: #F0F5FF; color: #2F54EB; }
|
||
.aa-select-option .check { visibility: hidden; margin-left: auto; }
|
||
.aa-select-option.is-selected .check { visibility: visible; }
|
||
.aa-select-option.is-disabled { color: #BFBFBF; cursor: not-allowed; }
|
||
.aa-select-empty { padding: 16px 12px; text-align: center; color: #767676; font-size: 13px; }
|
||
</style>
|