Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ON-41699 # added onBlur validation for boolean, camera, `checkbox… #702

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- onBlur validation for `boolean`, `camera`, `checkboxes`, `files`, `location` and `radio` elements

### Fixed

- accessibility attributes for checkbox and radio labels
Expand Down
1 change: 1 addition & 0 deletions src/form-elements/FormElementBoolean.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function FormElementBoolean({
})
}}
aria-describedby={ariaDescribedby}
onBlur={setIsDirty}
/>
}
>
Expand Down
1 change: 1 addition & 0 deletions src/form-elements/FormElementCamera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ function FormElementCamera({
onClick={openCamera}
disabled={element.readOnly || isLoading}
aria-describedby={ariaDescribedby}
onBlur={setIsDirty}
>
Open Camera
</button>
Expand Down
10 changes: 10 additions & 0 deletions src/form-elements/FormElementCheckBoxes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ function FormElementCheckboxes({
},
)}
aria-describedby={ariaDescribedby}
onBlur={() => {
if (index === filteredOptions.length - 1) {
setIsDirty()
}
}}
/>
)
})}
Expand Down Expand Up @@ -189,6 +194,11 @@ function FormElementCheckboxes({
inputProps={{
'aria-describedby': ariaDescribedby,
}}
onBlur={() => {
if (index === filteredOptions.length - 1) {
setIsDirty()
}
}}
/>{' '}
{option.label}
</label>
Expand Down
1 change: 1 addition & 0 deletions src/form-elements/FormElementFiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function FormElementFiles({
className="button ob-files__add-new-button"
onClick={handleAdd}
aria-describedby={ariaDescribedby}
onBlur={setIsDirty}
>
<MaterialIcon className="icon-x-large">add</MaterialIcon>
</button>
Expand Down
1 change: 1 addition & 0 deletions src/form-elements/FormElementLocation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ function FormElementLocation({
className="is-primary button ob-button ob-button__edit ob-location__button ob-location__button-edit cypress-locate-button"
onClick={onLocate}
disabled={element.readOnly}
onBlur={setIsDirty}
>
Locate
</button>
Expand Down
8 changes: 7 additions & 1 deletion src/form-elements/FormElementRadio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function FormElementRadio({
className="ob-radio-container"
aria-labelledby={`${id}-label`}
aria-describedby={ariaDescribedby}
onBlur={setIsDirty}
>
{filteredOptions.map((option) => (
<div className="control" key={option.value}>
Expand Down Expand Up @@ -111,7 +112,7 @@ function FormElementRadio({
aria-labelledby={`${id}-label`}
aria-describedby={ariaDescribedby}
>
{filteredOptions.map((option) => {
{filteredOptions.map((option, index) => {
const isSelected = value === option.value
return (
<div className="ob-button-radio-container" key={option.value}>
Expand All @@ -132,6 +133,11 @@ function FormElementRadio({
'is-light': !isSelected,
},
)}
onBlur={() => {
if (index === filteredOptions.length - 1) {
setIsDirty()
}
}}
/>
</div>
)
Expand Down
3 changes: 3 additions & 0 deletions src/form-elements/OptionButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Props = {
isSelected: boolean
onClick: () => void
className: string
onBlur?: () => void
'aria-describedby'?: string
}
const OptionButton = ({
Expand All @@ -18,6 +19,7 @@ const OptionButton = ({
isSelected,
onClick,
className,
onBlur,
...props
}: Props) => {
const buttonContrastColor = useContrastColor(option.colour)
Expand All @@ -33,6 +35,7 @@ const OptionButton = ({
disabled={element.readOnly}
onClick={onClick}
aria-describedby={props['aria-describedby']}
onBlur={onBlur}
>
{option.label}
</button>
Expand Down