Skip to content
Open
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
2 changes: 2 additions & 0 deletions docs/component-adapter/component-inventory.md
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,8 @@ The props for this component are defined in [BaseListProps](#baselistprops).
| **name** | `string` | No | - |
| **type** | `"number" \| "submit" \| "reset" \| "button" \| "checkbox" \| "color" \| "date" \| "datetime-local" \| "email" \| "file" \| "hidden" \| "image" \| "month" \| "password" \| "radio" \| "range" \| "search" \| "tel" \| "text" \| "time" \| "url" \| "week" \| string` | No | - |
| **placeholder** | `string` | No | - |
| **min** | `string \| number` | No | - |
| **max** | `string \| number` | No | - |
| **aria-describedby** | `string` | No | Identifies the element (or elements) that describes the object. |

## TextProps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,33 @@ export const WithDefaultValues: Story = () => {
</FormWrapper>
)
}

export const NumberInputWithMinMax: Story = () => {
return (
<FormWrapper>
<TextInputField
label="Age"
name="age"
type="number"
min={0}
max={120}
description="Enter a value between 0 and 120"
/>
<TextInputField
label="Hours Worked"
name="hoursWorked"
type="number"
min={0}
description="Cannot be negative"
/>
<TextInputField
label="Score"
name="score"
type="number"
min={0}
max={100}
description="Enter a score from 0 to 100"
/>
</FormWrapper>
)
}
8 changes: 8 additions & 0 deletions src/components/Common/UI/TextInput/TextInput.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ describe('TextInput', () => {
expect(screen.getByText('This field is required')).toBeInTheDocument()
})

it('applies min and max attributes to number input', () => {
renderWithProviders(<TextInput {...defaultProps} type="number" min={0} max={100} />)

const input = screen.getByRole('spinbutton')
expect(input).toHaveAttribute('min', '0')
expect(input).toHaveAttribute('max', '100')
})

describe('Accessibility', () => {
const testCases = [
{
Expand Down
4 changes: 4 additions & 0 deletions src/components/Common/UI/TextInput/TextInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export function TextInput(rawProps: TextInputProps) {
shouldVisuallyHideLabel,
adornmentEnd,
adornmentStart,
min,
max,
'aria-describedby': ariaDescribedByFromProps,
...otherProps
} = resolvedProps
Expand Down Expand Up @@ -69,6 +71,8 @@ export function TextInput(rawProps: TextInputProps) {
isDisabled={isDisabled}
adornmentStart={adornmentStart}
adornmentEnd={adornmentEnd}
min={min}
max={max}
/>
</FieldLayout>
)
Expand Down
2 changes: 1 addition & 1 deletion src/components/Common/UI/TextInput/TextInputTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface TextInputProps
SharedFieldLayoutProps,
Pick<
InputHTMLAttributes<HTMLInputElement>,
'name' | 'id' | 'placeholder' | 'className' | 'type'
'name' | 'id' | 'placeholder' | 'className' | 'type' | 'min' | 'max'
>,
Pick<InputHTMLAttributes<HTMLInputElement>, 'aria-describedby'> {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const EditContractorPaymentPresentation = ({ onSave, onCancel }: EditPaym
<NumberInputField
name="hours"
isRequired
min={0}
label={t('hoursLabel')}
adornmentEnd={t('hoursAdornment')}
/>
Expand All @@ -93,16 +94,23 @@ export const EditContractorPaymentPresentation = ({ onSave, onCancel }: EditPaym
{wageType === 'Fixed' && (
<Flex flexDirection="column" gap={16}>
<Heading as="h3">{t('fixedPaySection')}</Heading>
<NumberInputField name="wage" isRequired label={t('wageLabel')} format="currency" />
<NumberInputField
name="wage"
isRequired
min={0}
label={t('wageLabel')}
format="currency"
/>
</Flex>
)}

<Flex flexDirection="column" gap={16}>
<Heading as="h3">{t('additionalEarningsSection')}</Heading>
<Grid gridTemplateColumns={{ base: '1fr', small: [200, 200] }} gap={16}>
<NumberInputField name="bonus" label={t('bonusLabel')} format="currency" />
<NumberInputField name="bonus" min={0} label={t('bonusLabel')} format="currency" />
<NumberInputField
name="reimbursement"
min={0}
label={t('reimbursementLabel')}
format="currency"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ export const PayrollEditEmployeePresentation = ({
<TextInputField
key={compensationName}
type="number"
min={0}
adornmentEnd={t('hoursUnit')}
isRequired
label={getCompensationLabel(compensationName)}
Expand Down Expand Up @@ -445,6 +446,7 @@ export const PayrollEditEmployeePresentation = ({
<TextInputField
key={fixedCompensation.name}
type="number"
min={0}
adornmentStart="$"
isRequired
label={getFixedCompensationLabel(fixedCompensation.name)}
Expand All @@ -460,6 +462,7 @@ export const PayrollEditEmployeePresentation = ({
<Grid gridTemplateColumns={{ base: '1fr', small: [320, 320] }} gap={20}>
<TextInputField
type="number"
min={0}
adornmentStart="$"
isRequired
label={getFixedCompensationLabel(reimbursement.name)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const TimeOffField = ({ timeOff, employee }: TimeOffFieldProps) => {
key={timeOff.name}
name={`timeOffCompensations.${timeOff.name}`}
type="number"
min={0}
adornmentEnd={t('hoursUnit')}
isRequired
label={timeOff.name}
Expand Down