Skip to content

Commit f4c09b4

Browse files
committed
Add tabindex="-1" to right arrow icons in EditableTable component snapshots for accessibility improvements
1 parent 2005a01 commit f4c09b4

File tree

4 files changed

+1163
-154
lines changed

4 files changed

+1163
-154
lines changed

packages/field/src/components/Select/index.tsx

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -259,19 +259,22 @@ export const useFieldFetchData = (
259259
let i = 0;
260260
while (i < length) {
261261
const cur = _options[i++];
262-
if (cur[children] || cur[label] || cur[value]) {
263-
cur[type] =
264-
cur[
265-
type === 'children' ? children : type === 'label' ? label : value
266-
];
267-
traverseFieldKey(cur[children], type);
262+
const customFieldName =
263+
type === 'children' ? children : type === 'label' ? label : value;
264+
if (customFieldName && cur[customFieldName] !== undefined) {
265+
cur[type] = cur[customFieldName];
266+
if (type === 'children') {
267+
traverseFieldKey(cur[customFieldName], 'children');
268+
traverseFieldKey(cur[customFieldName], 'label');
269+
traverseFieldKey(cur[customFieldName], 'value');
270+
}
268271
}
269272
}
270273
};
271274

272275
if (children) traverseFieldKey(data, 'children');
273276
if (label) traverseFieldKey(data, 'label');
274-
if (value) traverseFieldKey(data, 'value');
277+
if (value) traverseFieldKey(data, 'value');
275278
return data;
276279
}, [fieldProps]);
277280

@@ -375,7 +378,8 @@ export const useFieldFetchData = (
375378
const applyFieldNamesMapping = (item: any) => {
376379
if (!fieldProps?.fieldNames) return item;
377380

378-
const { label: labelKey = 'label', value: valueKey = 'value' } = fieldProps.fieldNames;
381+
const { label: labelKey = 'label', value: valueKey = 'value' } =
382+
fieldProps.fieldNames;
379383

380384
return {
381385
...item,
@@ -450,6 +454,16 @@ const FieldSelect: ProFieldFC<
450454
const optionsValueEnum = useMemo(() => {
451455
if (mode !== 'read') return;
452456

457+
/**
458+
* Support select fieldNames
459+
* Similar to cascader fieldNames support
460+
*/
461+
const {
462+
value: valuePropsName = 'value',
463+
label: labelPropsName = 'label',
464+
options: optionsPropsName = 'options',
465+
} = fieldProps?.fieldNames || {};
466+
453467
const traverseOptions = (_options: typeof options) => {
454468
const localMap = new Map();
455469

@@ -461,12 +475,18 @@ const FieldSelect: ProFieldFC<
461475
for (let i = 0; i < length; i++) {
462476
const cur = _options[i];
463477

464-
if (cur.value !== undefined && cur.label !== undefined) {
465-
localMap.set(cur.value, cur.label);
478+
// Use fieldNames mapping to get correct value and label
479+
const curValue = cur[valuePropsName];
480+
const curLabel = cur[labelPropsName];
481+
482+
if (curValue !== undefined && curLabel !== undefined) {
483+
localMap.set(curValue, curLabel);
466484
}
467485

468-
if (cur.options?.length) {
469-
const childMap = traverseOptions(cur.options);
486+
// Handle nested options with fieldNames mapping
487+
const childOptions = cur[optionsPropsName] || cur.options;
488+
if (childOptions?.length) {
489+
const childMap = traverseOptions(childOptions);
470490
childMap.forEach((v, k) => localMap.set(k, v));
471491
}
472492
}
@@ -475,7 +495,7 @@ const FieldSelect: ProFieldFC<
475495
};
476496

477497
return traverseOptions(options);
478-
}, [mode, options]);
498+
}, [mode, options, fieldProps?.fieldNames]);
479499

480500
if (mode === 'read') {
481501
const dom = (

tests/card/__snapshots__/demo.test.ts.snap

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7541,6 +7541,57 @@ exports[`card demos > 📸 renders ./packages/card/src/demos/collapsible.tsx cor
75417541
aria-label="right"
75427542
class="anticon anticon-right ant-pro-card-collapsible-icon"
75437543
role="img"
7544+
tabindex="-1"
7545+
>
7546+
<svg
7547+
aria-hidden="true"
7548+
data-icon="right"
7549+
fill="currentColor"
7550+
focusable="false"
7551+
height="1em"
7552+
viewBox="64 64 896 896"
7553+
width="1em"
7554+
>
7555+
<path
7556+
d="M765.7 486.8L314.9 134.7A7.97 7.97 0 00302 141v77.3c0 4.9 2.3 9.6 6.1 12.6l360 281.1-360 281.1c-3.9 3-6.1 7.7-6.1 12.6V883c0 6.7 7.7 10.4 12.9 6.3l450.8-352.1a31.96 31.96 0 000-50.4z"
7557+
/>
7558+
</svg>
7559+
</span>
7560+
Collapsible
7561+
</div>
7562+
<div
7563+
class="ant-pro-card-extra"
7564+
>
7565+
<button
7566+
class="ant-btn ant-btn-default ant-btn-color-default ant-btn-variant-outlined ant-btn-sm"
7567+
type="button"
7568+
>
7569+
<span>
7570+
Submit
7571+
</span>
7572+
</button>
7573+
</div>
7574+
</div>
7575+
<div
7576+
class="ant-pro-card-body"
7577+
>
7578+
Content
7579+
</div>
7580+
</div>
7581+
<div
7582+
class="ant-pro-card ant-pro-card-collapse"
7583+
>
7584+
<div
7585+
class="ant-pro-card-header ant-pro-card-header-border ant-pro-card-header-collapsible"
7586+
>
7587+
<div
7588+
class="ant-pro-card-title"
7589+
>
7590+
<span
7591+
aria-label="right"
7592+
class="anticon anticon-right ant-pro-card-collapsible-icon"
7593+
role="img"
7594+
tabindex="-1"
75447595
>
75457596
<svg
75467597
aria-hidden="true"
@@ -7590,6 +7641,7 @@ exports[`card demos > 📸 renders ./packages/card/src/demos/collapsible.tsx cor
75907641
aria-label="right"
75917642
class="anticon anticon-right ant-pro-card-collapsible-icon"
75927643
role="img"
7644+
tabindex="-1"
75937645
>
75947646
<svg
75957647
aria-hidden="true"
@@ -7639,6 +7691,7 @@ exports[`card demos > 📸 renders ./packages/card/src/demos/collapsible.tsx cor
76397691
aria-label="right"
76407692
class="anticon anticon-right ant-pro-card-collapsible-icon"
76417693
role="img"
7694+
tabindex="-1"
76427695
>
76437696
<svg
76447697
aria-hidden="true"
@@ -8166,6 +8219,7 @@ exports[`card demos > 📸 renders ./packages/card/src/demos/group.tsx correctly
81668219
aria-label="right"
81678220
class="anticon anticon-right ant-pro-card-collapsible-icon"
81688221
role="img"
8222+
tabindex="-1"
81698223
>
81708224
<svg
81718225
aria-hidden="true"

0 commit comments

Comments
 (0)