Skip to content

Commit

Permalink
Add unit select to QuestionQuantity widget
Browse files Browse the repository at this point in the history
Refs: #323
  • Loading branch information
atuonufure committed Nov 5, 2024
1 parent f17e0c3 commit 23b63a7
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/components/BaseQuestionnaireResponseForm/widgets/number.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Form, InputNumber } from 'antd';
import { Form, InputNumber, Select } from 'antd';
import { Coding } from 'fhir/r4b';
import { useState } from 'react';
import { QuestionItemProps } from 'sdc-qrf';

import { useFieldController } from '../hooks';
Expand Down Expand Up @@ -59,10 +60,29 @@ export function QuestionQuantity(props: QuestionItemProps) {
const fieldName = [...parentPath, linkId, 0, 'value', 'decimal'];
const { value, onChange, disabled, formItem, placeholder } = useFieldController(fieldName, questionItem);

const [selectedUnit, setSelectedUnit] = useState(unitOption?.[0]?.display);

return (
<Form.Item {...formItem}>
<InputNumber
addonAfter={unitOption?.display}
addonAfter={
unitOption && unitOption.length > 1 ? (
<Select
value={selectedUnit}
onChange={setSelectedUnit}
style={{ minWidth: 70 }}
disabled={disabled}
>
{unitOption.map((option, index) => (
<Select.Option key={index} value={option.display}>
{option.display}
</Select.Option>
))}
</Select>
) : (
unitOption?.[0]?.display
)
}
style={inputStyle}
disabled={disabled}
onChange={onChange}
Expand Down

0 comments on commit 23b63a7

Please sign in to comment.