Skip to content

Commit e81abe3

Browse files
committed
fix: form htmlFor not work, close #5384
1 parent 86e69d3 commit e81abe3

File tree

5 files changed

+60
-58
lines changed

5 files changed

+60
-58
lines changed

components/_util/pickAttrs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ alt async autocomplete autofocus autoplay capture cellpadding cellspacing challe
33
charset checked classid classname colspan cols content contenteditable contextmenu
44
controls coords crossorigin data datetime default defer dir disabled download draggable
55
enctype form formaction formenctype formmethod formnovalidate formtarget frameborder
6-
headers height hidden high href hreflang htmlfor httpequiv icon id inputmode integrity
6+
headers height hidden high href hreflang htmlfor for httpequiv icon id inputmode integrity
77
is keyparams keytype kind label lang list loop low manifest marginheight marginwidth max maxlength media
88
mediagroup method min minlength multiple muted name novalidate nonce open
99
optimum pattern placeholder poster preload radiogroup readonly rel required

components/form/FormItem.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,11 @@ export default defineComponent({
304304
validateDisabled.value = false;
305305
});
306306
};
307-
307+
const htmlFor = computed(() => {
308+
return props.htmlFor === undefined ? fieldId.value : props.htmlFor;
309+
});
308310
const onLabelClick = () => {
309-
const id = fieldId.value;
311+
const id = htmlFor.value;
310312
if (!id || !inputRef.value) {
311313
return;
312314
}
@@ -409,7 +411,7 @@ export default defineComponent({
409411
{/* Label */}
410412
<FormItemLabel
411413
{...props}
412-
htmlFor={fieldId.value}
414+
htmlFor={htmlFor.value}
413415
required={isRequired.value}
414416
requiredMark={formContext.requiredMark.value}
415417
prefixCls={prefixCls.value}

components/form/FormItemLabel.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const FormItemLabel: FunctionalComponent<FormItemLabelProps> = (props, { slots,
8585
return (
8686
<Col {...mergedLabelCol} class={labelColClassName}>
8787
<label
88-
html-for={htmlFor}
88+
for={htmlFor}
8989
class={labelClassName}
9090
title={typeof label === 'string' ? label : ''}
9191
onClick={e => emit('click', e)}

0 commit comments

Comments
 (0)