Skip to content

Commit

Permalink
feat(DatePickerInput): add helperText support (#9200)
Browse files Browse the repository at this point in the history
* feat(DatePickerInput): add helperText support

* chore: update snapshots

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
emyarod and kodiakhq[bot] authored Jul 19, 2021
1 parent 66315c6 commit 4b5b5fd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2324,6 +2324,9 @@ Map {
"disabled": Object {
"type": "bool",
},
"helperText": Object {
"type": "node",
},
"hideLabel": Object {
"type": "bool",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const props = {
'mm/dd/yyyy'
),
disabled: boolean('Disabled (disabled in <DatePickerInput>)', false),
helperText: text('Helper text (helperText)', 'Optional help text'),
invalid: boolean(
'Show form validation UI (invalid in <DatePickerInput>)',
false
Expand Down
15 changes: 15 additions & 0 deletions packages/react/src/components/DatePickerInput/DatePickerInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export default class DatePickerInput extends Component {
*/
disabled: PropTypes.bool,

/**
* Provide text that is used alongside the control label for additional help
*/
helperText: PropTypes.node,

/**
* Specify if the label should be hidden
*/
Expand Down Expand Up @@ -137,6 +142,7 @@ export default class DatePickerInput extends Component {
disabled,
invalid,
invalidText,
helperText,
hideLabel,
onChange,
onClick,
Expand Down Expand Up @@ -179,6 +185,10 @@ export default class DatePickerInput extends Component {
[`${prefix}--label--disabled`]: disabled,
});

const helperTextClasses = classNames(`${prefix}--form__helper-text`, {
[`${prefix}--form__helper-text--disabled`]: disabled,
});

const inputClasses = classNames(`${prefix}--date-picker__input`, {
[`${prefix}--date-picker__input--${size}`]: size,
[`${prefix}--date-picker__input--invalid`]: invalid,
Expand Down Expand Up @@ -222,6 +232,10 @@ export default class DatePickerInput extends Component {
</label>
) : null;

const helper = helperText ? (
<div className={helperTextClasses}>{helperText}</div>
) : null;

let error = null;
if (invalid) {
error = (
Expand Down Expand Up @@ -266,6 +280,7 @@ export default class DatePickerInput extends Component {
{datePickerIcon}
</div>
{error}
{helper}
</div>
);
}
Expand Down

0 comments on commit 4b5b5fd

Please sign in to comment.