Skip to content

Commit 250d75e

Browse files
feat: validation class prop (#1181)
* feat: add props to FormValidationOverlay and Checkbox * fix: place className prop in correct wrapper element * fix: remove validationOverlayProps * fix: remove validationOverlayProps PropType definiton * chore: add unit test for validationClassName
1 parent c5c3bc3 commit 250d75e

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/Forms/Checkbox.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const Checkbox = React.forwardRef(({
2929
name,
3030
onChange,
3131
value,
32+
validationClassName,
3233
validationState,
3334
...props
3435
}, ref) => {
@@ -95,6 +96,7 @@ const Checkbox = React.forwardRef(({
9596

9697
return validationState ? (
9798
<FormValidationOverlay
99+
className={validationClassName}
98100
control={checkbox}
99101
validationState={validationState} />
100102
) : checkbox;
@@ -141,6 +143,8 @@ Please ensure you are either using a visible \`FormLabel\` or an \`aria-label\`
141143
labelProps: PropTypes.object,
142144
/** Sets the `name` for the checkbox input */
143145
name: PropTypes.string,
146+
/** Additional classes to apply to validation popover */
147+
validationClassName: PropTypes.string,
144148
/** An object identifying a validation message. The object will include properties for `state` and `text`; _e.g._, \`{ state: \'warning\', text: \'This is your last warning\' }\` */
145149
validationState: PropTypes.shape({
146150
/** State of validation: 'error', 'warning', 'information', 'success' */

src/Forms/Checkbox.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,17 @@ describe('<Checkbox />', () => {
118118
wrapper.find('.fd-checkbox').getDOMNode().classList
119119
).toContain('wonderful-styles');
120120
});
121+
122+
test('should set validationClassName on the popover', () => {
123+
const wrapper = setup({
124+
validationState: { state: 'error', text: 'Test validation state' },
125+
validationClassName: 'wonderful-styles'
126+
});
127+
128+
expect(
129+
wrapper.find('.fd-popover').getDOMNode().classList
130+
).toContain('wonderful-styles');
131+
});
121132
});
122133

123134
test('forwards the ref', () => {

src/Forms/_FormValidationOverlay.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ FormValidationOverlay.propTypes = {
5757
/** State of validation: 'error', 'warning', 'information', 'success' */
5858
state: PropTypes.oneOf(FORM_MESSAGE_TYPES),
5959
/** Text of the validation message */
60-
text: PropTypes.stringng
60+
text: PropTypes.string
6161
})
6262
};
6363

0 commit comments

Comments
 (0)