Skip to content

Commit

Permalink
Remove placeholder prop from Monthpicker component
Browse files Browse the repository at this point in the history
The `placeholder` prop was removed from the Monthpicker component as it was redundant. The input field now uses a default placeholder of 'yyyy-mm' directly within the MonthPicker.Input. Additionally, a new function getEksisterendeVerdi was introduced to handle specific period logic for field names including 'navArbeidsforholdPeriode'.
  • Loading branch information
krharum committed Oct 2, 2024
1 parent d7b9359 commit a868383
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ interface MonthpickerProps {
onChange?: (date: Date) => void
minDate?: Date
maxDate?: Date
placeholder?: string
}

export const Monthpicker = ({
Expand All @@ -25,10 +24,18 @@ export const Monthpicker = ({
onChange,
minDate = null,
maxDate = null,
placeholder = null,
}: MonthpickerProps) => {
const formMethods = useFormContext()
const eksisterendeVerdi = formMethods.watch(name)
const val = formMethods.watch(name)

function getEksisterendeVerdi() {
if (name.includes('navArbeidsforholdPeriode')) {
return val?.year ? new Date(val?.year, val?.monthValue) : null
}
return val
}

const eksisterendeVerdi = getEksisterendeVerdi()

const formattedDate =
eksisterendeVerdi instanceof Date
Expand Down Expand Up @@ -61,12 +68,7 @@ export const Monthpicker = ({
<InputWrapper size={'small'}>
<Label name={name} label={label}>
<MonthPicker {...monthpickerProps} dropdownCaption={true} selected={formattedDate}>
<MonthPicker.Input
label={null}
size={'small'}
placeholder={placeholder || 'yyyy-mm'}
{...inputProps}
/>
<MonthPicker.Input label={null} size={'small'} placeholder={'yyyy-mm'} {...inputProps} />
</MonthPicker>
</Label>
</InputWrapper>
Expand Down

0 comments on commit a868383

Please sign in to comment.