diff --git a/src/components/decimal/decimal.stories.mdx b/src/components/decimal/decimal.stories.mdx index 663139b474..f00d766221 100644 --- a/src/components/decimal/decimal.stories.mdx +++ b/src/components/decimal/decimal.stories.mdx @@ -105,6 +105,12 @@ import Decimal from "carbon-react/lib/components/decimal"; +### With inputHint + + + + + ### With labelHelp diff --git a/src/components/decimal/decimal.stories.tsx b/src/components/decimal/decimal.stories.tsx index 2af4d730ec..c69921fe76 100644 --- a/src/components/decimal/decimal.stories.tsx +++ b/src/components/decimal/decimal.stories.tsx @@ -108,6 +108,11 @@ WithLabelHelp.args = { helpAriaLabel: "Help", }; +export const WithInputHint = DefaultStory.bind({}); +WithInputHint.args = { + inputHint: "Hint text (optional).", +}; + export const Required = DefaultStory.bind({}); Required.args = { required: true }; diff --git a/src/components/grouped-character/grouped-character.stories.mdx b/src/components/grouped-character/grouped-character.stories.mdx index bc16847f93..a0a00d5bb4 100644 --- a/src/components/grouped-character/grouped-character.stories.mdx +++ b/src/components/grouped-character/grouped-character.stories.mdx @@ -114,6 +114,15 @@ import GroupedCharacter from "carbon-react/lib/components/grouped-character"; +### with inputHint + +When the `inputHint` prop is passed, please use a full stop `.` at the end. This forces a pause +before any other announcements, this well help screen reader users understand the hint fully. + + + + + ### With labelHelp diff --git a/src/components/grouped-character/grouped-character.stories.tsx b/src/components/grouped-character/grouped-character.stories.tsx index 4d90cd0b14..1e30987d6c 100644 --- a/src/components/grouped-character/grouped-character.stories.tsx +++ b/src/components/grouped-character/grouped-character.stories.tsx @@ -149,6 +149,25 @@ export const FieldHelp = () => { ); }; +export const InputHint = () => { + const [state, setState] = useState("1231231"); + + const setValue = ({ target }: CustomEvent) => { + setState(target.value.rawValue); + }; + + return ( + + ); +}; + export const LabelHelp = () => { const [state, setState] = useState("1231231"); diff --git a/src/components/number/number.stories.mdx b/src/components/number/number.stories.mdx index 0390d8ec12..345aa62fb0 100644 --- a/src/components/number/number.stories.mdx +++ b/src/components/number/number.stories.mdx @@ -88,6 +88,15 @@ import Number from "carbon-react/lib/components/number"; +### with inputHint + +When the `inputHint` prop is passed, please use a full stop `.` at the end. This forces a pause +before any other announcements, this well help screen reader users understand the hint fully. + + + + + ### With labelHelp diff --git a/src/components/number/number.stories.tsx b/src/components/number/number.stories.tsx index edd4528db2..6aaf1a98f8 100644 --- a/src/components/number/number.stories.tsx +++ b/src/components/number/number.stories.tsx @@ -86,6 +86,10 @@ export const WithFieldHelp: ComponentStory = () => ( ); +export const WithInputHint: ComponentStory = () => ( + +); + export const WithLabelHelp: ComponentStory = () => ( ); diff --git a/src/components/password/password.stories.mdx b/src/components/password/password.stories.mdx index b8d8dede57..1f2d73e34a 100644 --- a/src/components/password/password.stories.mdx +++ b/src/components/password/password.stories.mdx @@ -61,6 +61,9 @@ the input type will not be able to be changed to `text`. To be used primarily to ### with inputHint +When the `inputHint` prop is passed, please use a full stop `.` at the end. This forces a pause +before any other announcements, this well help screen reader users understand the hint fully. + diff --git a/src/components/password/password.stories.tsx b/src/components/password/password.stories.tsx index d32e2c149f..d83e77ad24 100644 --- a/src/components/password/password.stories.tsx +++ b/src/components/password/password.stories.tsx @@ -39,7 +39,7 @@ export const InputHint = () => { return ( { label={`${size} - ${validationType}`} value={state} onChange={setValue} - labelHelp="Hint text (optional)" + inputHint="Hint text (optional)" size={size} {...{ [validationType]: "Message" }} /> @@ -411,7 +411,7 @@ export const NewDesignsValidation = () => { label={`readOnly - ${size} - ${validationType}`} value="Password" size={size} - labelHelp="Hint text (optional)" + inputHint="Hint text (optional)." readOnly {...{ [validationType]: "Message" }} /> diff --git a/src/components/textarea/textarea.component.tsx b/src/components/textarea/textarea.component.tsx index f440061a95..9f1caef4e5 100644 --- a/src/components/textarea/textarea.component.tsx +++ b/src/components/textarea/textarea.component.tsx @@ -15,11 +15,7 @@ import StyledTextarea, { MIN_HEIGHT } from "./textarea.style"; import { TooltipProvider } from "../../__internal__/tooltip-provider"; import useInputAccessibility from "../../hooks/__internal__/useInputAccessibility"; import { NewValidationContext } from "../carbon-provider/carbon-provider.component"; -import { - ErrorBorder, - StyledHintText, - StyledInputHint, -} from "../textbox/textbox.style"; +import { ErrorBorder, StyledHintText } from "../textbox/textbox.style"; import ValidationMessage from "../../__internal__/validation-message"; import Box from "../box"; import Logger from "../../__internal__/utils/logger"; @@ -84,7 +80,10 @@ export interface TextareaProps label?: string; /** Inline label alignment */ labelAlign?: "left" | "right"; - /** Text applied to label help tooltip */ + /** [Legacy] Text applied to label help tooltip. When opted into new design validations + * it will render as a hint above the input, unless an `inputHint` + * prop is also passed + */ labelHelp?: React.ReactNode; /** When true, label is placed in line an input */ labelInline?: boolean; @@ -382,13 +381,10 @@ export const Textarea = React.forwardRef( adaptiveLabelBreakpoint={adaptiveLabelBreakpoint} validationRedesignOptIn={validationRedesignOptIn} > - {inputHint ? ( - - {inputHint} - - ) : null} - {validationRedesignOptIn && labelHelp && ( - {labelHelp} + {(inputHint || (labelHelp && validationRedesignOptIn)) && ( + + {inputHint || labelHelp} + )} {validationRedesignOptIn ? ( diff --git a/src/components/textarea/textarea.spec.tsx b/src/components/textarea/textarea.spec.tsx index a0c919f5cf..29d798a80a 100644 --- a/src/components/textarea/textarea.spec.tsx +++ b/src/components/textarea/textarea.spec.tsx @@ -21,11 +21,7 @@ import { StyledLabelContainer } from "../../__internal__/label/label.style"; import Tooltip from "../tooltip"; import StyledHelp from "../help/help.style"; import CarbonProvider from "../carbon-provider/carbon-provider.component"; -import { - ErrorBorder, - StyledHintText, - StyledInputHint, -} from "../textbox/textbox.style"; +import { ErrorBorder, StyledHintText } from "../textbox/textbox.style"; import StyledValidationMessage from "../../__internal__/validation-message/validation-message.style"; import StyledTextarea from "./textarea.style"; import Logger from "../../__internal__/utils/logger"; @@ -257,12 +253,12 @@ describe("Textarea", () => { describe("and inputHint props are present", () => { it("renders a character counter hint", () => { wrapper = mount(