& {
labelNode: React.JSX.Element | null;
validationId: string;
- helpId: string;
+ help: ReactNode;
}) => (
{isSelect ? (
@@ -160,12 +176,7 @@ const generateContent = ({
children
)}
{!labelFirst && labelNode}
- {generateHelpText({
- helpId,
- help,
- helpClassName,
- isTickElement,
- })}
+ {helpAfterLabel ? null : help}
{generateError(error, caution, success, validationId)}
);
@@ -178,6 +189,7 @@ const Field = ({
forId,
help,
helpClassName,
+ helpAfterLabel,
helpId,
isSelect,
isTickElement,
@@ -186,31 +198,40 @@ const Field = ({
labelFirst = true,
required,
stacked,
+ stackedFieldColumns = 8,
+ stackedLabelColumns = 4,
success,
validationId,
...props
}: Props): React.JSX.Element => {
+ const helpNode = generateHelpText({
+ helpId,
+ help,
+ helpClassName,
+ isTickElement,
+ });
const labelNode = generateLabel(
forId,
required,
label,
labelClassName,
stacked,
+ stackedLabelColumns,
+ helpNode,
+ helpAfterLabel,
);
const content = generateContent({
isSelect,
- isTickElement,
children,
labelFirst,
labelNode,
- help,
- helpClassName,
+ help: helpNode,
error,
caution,
success,
validationId,
- helpId,
+ helpAfterLabel,
});
return (
{labelFirst && labelNode}
- {stacked ?
{content} : content}
+ {stacked ? {content} : content}
);
};
diff --git a/src/components/Input/Input.tsx b/src/components/Input/Input.tsx
index 183d45a1..0c397fbd 100644
--- a/src/components/Input/Input.tsx
+++ b/src/components/Input/Input.tsx
@@ -7,6 +7,7 @@ import CheckboxInput from "../CheckboxInput";
import RadioInput from "../RadioInput";
import type { ClassName, PropsWithSpread } from "types";
+import { ColSize } from "components/Col";
/**
* The props for the Input component.
@@ -37,6 +38,10 @@ export type Props = PropsWithSpread<
* The id of the input.
*/
id?: string;
+ /**
+ * Whether the help should appear after the label (by default it will appear below the field).
+ */
+ helpAfterLabel?: boolean;
/**
* The label for the field.
*/
@@ -53,6 +58,14 @@ export type Props = PropsWithSpread<
* Whether the form field should have a stacked appearance.
*/
stacked?: boolean;
+ /**
+ * The number of columns the field should have when stacked.
+ */
+ stackedFieldColumns?: ColSize;
+ /**
+ * The number of columns the label should have when stacked.
+ */
+ stackedLabelColumns?: ColSize;
/**
* The content for success validation.
*/
@@ -83,12 +96,15 @@ const Input = ({
className,
error,
help,
+ helpAfterLabel,
helpClassName,
id,
label,
labelClassName,
required,
stacked,
+ stackedFieldColumns,
+ stackedLabelColumns,
success,
takeFocus,
takeFocusDelay,
@@ -160,6 +176,7 @@ const Input = ({
error={error}
forId={inputId}
help={help}
+ helpAfterLabel={helpAfterLabel}
helpClassName={helpClassName}
helpId={helpId}
isTickElement={type === "checkbox" || type === "radio"}
@@ -167,6 +184,8 @@ const Input = ({
labelClassName={labelClassName}
required={required}
stacked={stacked}
+ stackedFieldColumns={stackedFieldColumns}
+ stackedLabelColumns={stackedLabelColumns}
success={success}
validationId={validationId}
>
diff --git a/src/components/Select/Select.tsx b/src/components/Select/Select.tsx
index 53483a48..1663e705 100644
--- a/src/components/Select/Select.tsx
+++ b/src/components/Select/Select.tsx
@@ -10,6 +10,7 @@ import type {
import Field from "../Field";
import type { ClassName, PropsWithSpread } from "types";
+import { ColSize } from "components/Col";
type Option = OptionHTMLAttributes;
@@ -34,6 +35,10 @@ export type Props = PropsWithSpread<
* Help text to show below the field.
*/
help?: ReactNode;
+ /**
+ * Whether the help should appear after the label (by default it will appear below the field).
+ */
+ helpAfterLabel?: boolean;
/**
* Optional class(es) to pass to the help text element.
*/
@@ -66,6 +71,14 @@ export type Props = PropsWithSpread<
* Whether the form field should have a stacked appearance.
*/
stacked?: boolean;
+ /**
+ * The number of columns the field should have when stacked.
+ */
+ stackedFieldColumns?: ColSize;
+ /**
+ * The number of columns the label should have when stacked.
+ */
+ stackedLabelColumns?: ColSize;
/**
* The content for success validation.
*/
@@ -99,6 +112,7 @@ const Select = ({
className,
error,
help,
+ helpAfterLabel,
helpClassName,
id,
label,
@@ -107,6 +121,8 @@ const Select = ({
options,
required,
stacked,
+ stackedFieldColumns,
+ stackedLabelColumns,
success,
takeFocus,
wrapperClassName,
@@ -132,6 +148,7 @@ const Select = ({
error={error}
forId={selectId}
help={help}
+ helpAfterLabel={helpAfterLabel}
helpClassName={helpClassName}
helpId={helpId}
isSelect={true}
@@ -139,6 +156,8 @@ const Select = ({
labelClassName={labelClassName}
required={required}
stacked={stacked}
+ stackedFieldColumns={stackedFieldColumns}
+ stackedLabelColumns={stackedLabelColumns}
success={success}
validationId={validationId}
>