Merge pull request #795 from lethemanh/771-numpad-on-number-textfield
#771 numpad on number textfield
This commit is contained in:
@@ -25,7 +25,18 @@ import { ReadOnlyDateField } from './components/ReadOnlyPickerField'
|
|||||||
import { LONG_DATE_FORMAT } from './utils/dateTimeFormatters'
|
import { LONG_DATE_FORMAT } from './utils/dateTimeFormatters'
|
||||||
import { FC_DAYS, WeekDaySelector } from './WeekDaySelector'
|
import { FC_DAYS, WeekDaySelector } from './WeekDaySelector'
|
||||||
|
|
||||||
export default function RepeatEvent({
|
const numericSlotProps = {
|
||||||
|
htmlInput: {
|
||||||
|
inputMode: 'numeric'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const RepeatEvent: React.FC<{
|
||||||
|
repetition: RepetitionObject
|
||||||
|
eventStart: Date
|
||||||
|
setRepetition: (repetition: RepetitionObject) => void
|
||||||
|
isOwn?: boolean
|
||||||
|
}> = ({
|
||||||
repetition,
|
repetition,
|
||||||
eventStart,
|
eventStart,
|
||||||
setRepetition,
|
setRepetition,
|
||||||
@@ -35,7 +46,7 @@ export default function RepeatEvent({
|
|||||||
eventStart: Date
|
eventStart: Date
|
||||||
setRepetition: (repetition: RepetitionObject) => void
|
setRepetition: (repetition: RepetitionObject) => void
|
||||||
isOwn?: boolean
|
isOwn?: boolean
|
||||||
}) {
|
}) => {
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const days = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU']
|
const days = ['MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU']
|
||||||
const day = new Date(eventStart)
|
const day = new Date(eventStart)
|
||||||
@@ -48,7 +59,7 @@ export default function RepeatEvent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fully derived — occurrences takes priority over endDate
|
// Fully derived — occurrences takes priority over endDate
|
||||||
const getEndOption = () => {
|
const getEndOption = (): 'after' | 'on' | 'never' => {
|
||||||
if (repetition.occurrences) return 'after'
|
if (repetition.occurrences) return 'after'
|
||||||
if (repetition.endDate) return 'on'
|
if (repetition.endDate) return 'on'
|
||||||
return 'never'
|
return 'never'
|
||||||
@@ -75,13 +86,16 @@ export default function RepeatEvent({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
size="small"
|
size="small"
|
||||||
style={{ width: 80 }}
|
sx={{ width: 80 }}
|
||||||
inputProps={{
|
slotProps={{
|
||||||
min: 1,
|
htmlInput: {
|
||||||
'data-testid': 'repeat-interval',
|
...numericSlotProps.htmlInput,
|
||||||
style: {
|
min: 1,
|
||||||
textAlign: 'center',
|
'data-testid': 'repeat-interval',
|
||||||
paddingRight: 5
|
style: {
|
||||||
|
textAlign: 'center',
|
||||||
|
paddingRight: 5
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
@@ -258,28 +272,12 @@ export default function RepeatEvent({
|
|||||||
control={<Radio />}
|
control={<Radio />}
|
||||||
sx={{ mt: 1 }}
|
sx={{ mt: 1 }}
|
||||||
label={
|
label={
|
||||||
<Box
|
<Box display="flex" alignItems="center" gap={1}>
|
||||||
display="flex"
|
|
||||||
alignItems="center"
|
|
||||||
gap={1}
|
|
||||||
onClick={() => {
|
|
||||||
if (!isOwn || endOption === 'after') return
|
|
||||||
setRepetition({
|
|
||||||
...repetition,
|
|
||||||
endDate: null,
|
|
||||||
occurrences:
|
|
||||||
repetition.occurrences && repetition.occurrences > 0
|
|
||||||
? repetition.occurrences
|
|
||||||
: 1
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Typography variant="h6">
|
<Typography variant="h6">
|
||||||
{t('event.repeat.end.after')}
|
{t('event.repeat.end.after')}
|
||||||
</Typography>
|
</Typography>
|
||||||
<TextField
|
<TextField
|
||||||
type="number"
|
type="number"
|
||||||
inputProps={{ min: 1, 'data-testid': 'occurrences-input' }}
|
|
||||||
size="small"
|
size="small"
|
||||||
value={repetition.occurrences || 1}
|
value={repetition.occurrences || 1}
|
||||||
onChange={e => {
|
onChange={e => {
|
||||||
@@ -290,8 +288,15 @@ export default function RepeatEvent({
|
|||||||
occurrences: value > 0 ? value : 1
|
occurrences: value > 0 ? value : 1
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
style={{ width: 100 }}
|
sx={{ width: 100 }}
|
||||||
disabled={!isOwn}
|
disabled={!isOwn}
|
||||||
|
slotProps={{
|
||||||
|
htmlInput: {
|
||||||
|
...numericSlotProps.htmlInput,
|
||||||
|
min: 1,
|
||||||
|
'data-testid': 'occurrences-input'
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<Typography variant="h6">
|
<Typography variant="h6">
|
||||||
{t('event.repeat.end.occurrences')}
|
{t('event.repeat.end.occurrences')}
|
||||||
@@ -305,3 +310,5 @@ export default function RepeatEvent({
|
|||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default RepeatEvent
|
||||||
|
|||||||
Reference in New Issue
Block a user