Skip to content

Commit

Permalink
Add default value for Solid Choice control on Search bar
Browse files Browse the repository at this point in the history
  • Loading branch information
vesnushka committed Dec 3, 2024
1 parent d643fcd commit 11cf04b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ import { SearchBarColumnSolidChoiceTypeProps } from '../types';

export function SolidChoiceColumn(props: SearchBarColumnSolidChoiceTypeProps) {
const { columnFilterValue } = props;
const { options, defaultValue } = columnFilterValue.column;
const { value } = columnFilterValue;
const { options } = columnFilterValue.column;

const { onSelect } = useSolidChoiceColumn(props);

return (
<Radio.Group defaultValue={defaultValue?.code} optionType="button" onChange={(e) => onSelect(e.target.value)}>
{options.map((c) => (
<Radio.Button key={c.code} value={c.code}>
{c.display}
// NOTE: Radio.Button defaultChecked and checked cannot be applied properly to check Coding value.
<Radio.Group value={value?.[0]?.code} onChange={(e) => onSelect(e.target.value)}>
{options.map((coding) => (
<Radio.Button key={`radio-button-${coding.code}`} value={coding.code}>
{coding.display}
</Radio.Button>
))}
</Radio.Group>
Expand Down
2 changes: 1 addition & 1 deletion src/components/SearchBar/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function useSearchBar(props: SearchBarProps): SearchBarData {
}

if (isSolidChoiceColumn(column)) {
return { column, value: null };
return { column, value: column.defaultValue ? [column.defaultValue] : null };
}

throw new Error('Unsupported column type');
Expand Down

0 comments on commit 11cf04b

Please sign in to comment.