Skip to content

Commit

Permalink
Merge pull request #513 from department-of-veterans-affairs/feature/4…
Browse files Browse the repository at this point in the history
…27-narin-checkbox-group-add-description

[Feature] CheckboxGroup – Add item descriptions
  • Loading branch information
narin authored Oct 3, 2024
2 parents 589e4d9 + 8132f93 commit e6d0c6f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/components/src/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const Checkbox: FC<CheckboxProps> = ({
...containerStyle,
borderLeftWidth: spacing.vadsSpace2xs,
borderColor: theme.vadsColorFormsBorderError,
paddingLeft: spacing.vadsSpaceLg,
paddingLeft: spacing.vadsSpaceMd,
}
}

Expand All @@ -73,7 +73,7 @@ export const Checkbox: FC<CheckboxProps> = ({
const tileStyle: ViewStyle = {
...pressableBaseStyle,
borderWidth: 2,
borderRadius: spacing.vadsSpace2xs,
borderRadius: 4,
padding: spacing.vadsSpaceSm,
paddingRight: spacing.vadsSpaceMd,
borderColor: checked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,15 @@ const statefulComponentRenderer = (props: CheckboxGroupProps) => {
}

const items = [
{ text: 'Option 1' },
{ text: 'Option 1', description: 'Description for option 1' },
{
text: 'Option 2',
a11yLabel: 'Accessibility override for option 2',
value: '2',
description: {
text: 'Description for option 2',
a11yLabel: 'Accessibility override for description',
},
},
{ text: 'Option 3' },
{ text: 'Option 4' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ import React, { FC, Fragment } from 'react'
import { Checkbox } from '../Checkbox/Checkbox'
import { ComponentWrapper } from '../../wrapper'
import { Error, Header, Hint } from '../shared/FormText'
import { FormElementProps, TextWithA11y } from '../../types'
import {
FormElementProps,
StringOrTextWithA11y,
TextWithA11y,
} from '../../types'
import { Spacer } from '../Spacer/Spacer'
import { useTheme } from '../../utils'

type TextWithA11yAndValue = TextWithA11y & {
/** Description for checkbox item */
description?: StringOrTextWithA11y
/** Value or ID for checkbox item if different than checkbox label */
value?: string | number
/** Optional TestID */
Expand Down Expand Up @@ -115,7 +121,7 @@ export const CheckboxGroup: FC<CheckboxGroupProps> = ({
...containerStyle,
borderLeftWidth: spacing.vadsSpace2xs,
borderColor: theme.vadsColorFormsBorderError,
paddingLeft: spacing.vadsSpaceLg,
paddingLeft: spacing.vadsSpaceMd,
}
}

Expand All @@ -139,6 +145,7 @@ export const CheckboxGroup: FC<CheckboxGroupProps> = ({
<Fragment key={`checkbox-group-item-${index}`}>
<Checkbox
label={item}
description={isObject ? item.description : undefined}
checked={selectedItems.includes(value)}
onPress={() => handleCheckboxChange(value)}
testID={isObject ? item.testID : undefined}
Expand Down

0 comments on commit e6d0c6f

Please sign in to comment.