Skip to content

Commit 402556b

Browse files
committed
change FieldSetColumnContext to use boolean tag value to detect wheter the component is in field set column
1 parent d209140 commit 402556b

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

src/scripts/FieldSet.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import { createFC } from './common';
66
/**
77
*
88
*/
9-
export const FieldSetColumnContext = createContext<{ totalCols?: number }>({});
9+
export const FieldSetColumnContext = createContext<{
10+
isFieldSetColumn?: boolean;
11+
totalCols?: number;
12+
}>({});
1013

1114
/**
1215
*
@@ -26,7 +29,10 @@ export const FieldSetRow = createFC<
2629
(props) => {
2730
const { className, cols, children } = props;
2831
const totalCols = cols || React.Children.count(children);
29-
const ctx = useMemo(() => ({ totalCols }), [totalCols]);
32+
const ctx = useMemo(
33+
() => ({ isFieldSetColumn: true, totalCols }),
34+
[totalCols]
35+
);
3036
const rowClassNames = classnames(className, 'slds-form-element__row');
3137
return (
3238
<FieldSetColumnContext.Provider value={ctx}>

src/scripts/Input.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ export const Input = createFC<InputProps, { isFormElement: boolean }>(
140140
...rprops
141141
} = props;
142142
const id = useFormElementId(id_, 'input');
143-
const { totalCols } = useContext(FieldSetColumnContext);
144-
if (label || required || error || totalCols || cols) {
143+
const { isFieldSetColumn } = useContext(FieldSetColumnContext);
144+
if (isFieldSetColumn || label || required || error || cols) {
145145
const formElemProps = {
146146
id,
147147
label,

src/scripts/Select.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ export const Select = createFC<SelectProps, { isFormElement: boolean }>(
2929
(props) => {
3030
const { id: id_ } = props;
3131
const id = useFormElementId(id_, 'select');
32-
const { totalCols } = useContext(FieldSetColumnContext);
32+
const { isFieldSetColumn } = useContext(FieldSetColumnContext);
3333
const { label, required, error, cols, elementRef, ...rprops } = props;
34-
if (label || required || error || totalCols || cols) {
34+
if (isFieldSetColumn || label || required || error || cols) {
3535
const formElemProps = { id, label, required, error, cols, elementRef };
3636
return (
3737
<FormElement {...formElemProps}>

src/scripts/Textarea.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ export const Textarea = createFC<TextareaProps, { isFormElement: boolean }>(
4646
...rprops
4747
} = props;
4848
const id = useFormElementId(id_, 'textarea');
49-
const { totalCols } = useContext(FieldSetColumnContext);
50-
if (label || required || error || totalCols || cols) {
49+
const { isFieldSetColumn } = useContext(FieldSetColumnContext);
50+
if (isFieldSetColumn || label || required || error || cols) {
5151
const formElemProps = {
5252
id,
5353
label,

0 commit comments

Comments
 (0)