Skip to content

Commit

Permalink
feat: add is-invalid class to WebformElementWrapper has error
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrsky committed Nov 30, 2019
1 parent 6aad5b4 commit ef33a36
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
8 changes: 1 addition & 7 deletions src/components/WebformCheckbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,7 @@ export const WebformCheckbox: WebformCustomComponent = ({ element, error }) => {
settings.attributes.title_display = 'after'

return (
<WebformElementWrapper
settings={settings}
error={error}
className="form-group form-check"
labelClassName="form-check-label"
labelFor={id}
>
<WebformElementWrapper settings={settings} error={error} className="form-check" labelClassName="form-check-label" labelFor={id}>
<input defaultChecked={!!defaultValue} {...inputProps} />
</WebformElementWrapper>
)
Expand Down
4 changes: 3 additions & 1 deletion src/components/WebformElementWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ const ElementWrapper: React.FC<Props> = ({ children, settings, error, labelFor,
</label>
)

const classNames = ['form-group', error != null && 'is-invalid', props.className].filter(item => typeof item === 'string').join(' ')

return (
<div className="form-group" {...props}>
<div {...props} className={classNames}>
{getTitleDisplay(attributes) === 'before' && label}

{children}
Expand Down

0 comments on commit ef33a36

Please sign in to comment.