fixed focus and min value (#999)

fixes: #405
This commit is contained in:
Erik Jan de Wit 2021-08-16 11:40:14 +02:00 committed by GitHub
parent 37f0010b81
commit 321b259a4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 8 deletions

View file

@ -37,6 +37,13 @@ export const TokenLifespan = ({
const { t } = useTranslation("clients"); const { t } = useTranslation("clients");
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const [focused, setFocused] = useState(false);
const onFocus = () => setFocused(true);
const onBlur = () => setFocused(false);
const isExpireSet = (value: string | number) =>
(typeof value === "number" && value !== -1) || focused;
return ( return (
<FormGroup <FormGroup
label={t(id)} label={t(id)}
@ -66,19 +73,22 @@ export const TokenLifespan = ({
onChange(value); onChange(value);
setOpen(false); setOpen(false);
}} }}
selections={[ selections={[isExpireSet(value) ? t(expires) : t(never)]}
typeof value === "number" && value !== -1
? t(expires)
: t(never),
]}
> >
<SelectOption value={-1}>{t(never)}</SelectOption> <SelectOption value={-1}>{t(never)}</SelectOption>
<SelectOption value={60}>{t(expires)}</SelectOption> <SelectOption value={60}>{t(expires)}</SelectOption>
</Select> </Select>
</SplitItem> </SplitItem>
<SplitItem> <SplitItem>
{typeof value === "number" && value !== -1 && ( {isExpireSet(value) && (
<TimeSelector units={units} value={value} onChange={onChange} /> <TimeSelector
units={units}
value={value}
onChange={onChange}
onFocus={onFocus}
onBlur={onBlur}
min={1}
/>
)} )}
</SplitItem> </SplitItem>
</Split> </Split>

View file

@ -24,6 +24,7 @@ export const TimeSelector = ({
units = ["seconds", "minutes", "hours", "days"], units = ["seconds", "minutes", "hours", "days"],
onChange, onChange,
className, className,
min,
...rest ...rest
}: TimeSelectorProps) => { }: TimeSelectorProps) => {
const { t } = useTranslation("common"); const { t } = useTranslation("common");
@ -84,7 +85,7 @@ export const TimeSelector = ({
type="number" type="number"
id={`kc-time-${new Date().getTime()}`} id={`kc-time-${new Date().getTime()}`}
aria-label="kc-time" aria-label="kc-time"
min="0" min={min || 0}
value={timeValue} value={timeValue}
className={`${className}-input`} className={`${className}-input`}
onChange={(value) => { onChange={(value) => {