@@ -5,7 +5,7 @@ import {
|
|||||||
} from "@/utils/timezone";
|
} from "@/utils/timezone";
|
||||||
import { TIMEZONES } from "@/utils/timezone-data";
|
import { TIMEZONES } from "@/utils/timezone-data";
|
||||||
import { Button, Popover } from "@linagora/twake-mui";
|
import { Button, Popover } from "@linagora/twake-mui";
|
||||||
import { MouseEvent, useMemo, useState } from "react";
|
import { MouseEvent, useMemo, useRef, useState } from "react";
|
||||||
import { useI18n } from "twake-i18n";
|
import { useI18n } from "twake-i18n";
|
||||||
import { TimezoneAutocomplete } from "../Timezone/TimezoneAutocomplete";
|
import { TimezoneAutocomplete } from "../Timezone/TimezoneAutocomplete";
|
||||||
|
|
||||||
@@ -21,6 +21,7 @@ export function TimezoneSelector({
|
|||||||
referenceDate,
|
referenceDate,
|
||||||
}: TimezoneSelectProps) {
|
}: TimezoneSelectProps) {
|
||||||
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
|
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
|
||||||
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
|
|
||||||
const timezoneList = useTimeZoneList();
|
const timezoneList = useTimeZoneList();
|
||||||
|
|
||||||
@@ -72,6 +73,11 @@ export function TimezoneSelector({
|
|||||||
paper: {
|
paper: {
|
||||||
sx: { width: 280, maxHeight: 400, overflow: "hidden", p: 0 },
|
sx: { width: 280, maxHeight: 400, overflow: "hidden", p: 0 },
|
||||||
},
|
},
|
||||||
|
transition: {
|
||||||
|
onEntered: () => {
|
||||||
|
inputRef.current?.focus();
|
||||||
|
},
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<TimezoneAutocomplete
|
<TimezoneAutocomplete
|
||||||
@@ -82,7 +88,8 @@ export function TimezoneSelector({
|
|||||||
getTimezoneOffset={(tzName: string) =>
|
getTimezoneOffset={(tzName: string) =>
|
||||||
getTimezoneOffset(tzName, referenceDate)
|
getTimezoneOffset(tzName, referenceDate)
|
||||||
}
|
}
|
||||||
autoFocus={true}
|
inputRef={inputRef}
|
||||||
|
openOnFocus
|
||||||
showIcon={false}
|
showIcon={false}
|
||||||
inputFontSize="14px"
|
inputFontSize="14px"
|
||||||
inputPadding="2px 4px"
|
inputPadding="2px 4px"
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ interface TimezoneAutocompleteProps {
|
|||||||
zones: string[];
|
zones: string[];
|
||||||
getTimezoneOffset: (tzName: string) => string;
|
getTimezoneOffset: (tzName: string) => string;
|
||||||
showIcon?: boolean;
|
showIcon?: boolean;
|
||||||
autoFocus?: boolean;
|
inputRef?: React.Ref<HTMLInputElement>;
|
||||||
width?: number | string;
|
width?: number | string;
|
||||||
size?: "small" | "medium";
|
size?: "small" | "medium";
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
@@ -23,6 +23,7 @@ interface TimezoneAutocompleteProps {
|
|||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
disableClearable?: boolean;
|
disableClearable?: boolean;
|
||||||
hideBorder?: boolean;
|
hideBorder?: boolean;
|
||||||
|
openOnFocus?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TimezoneAutocomplete({
|
export function TimezoneAutocomplete({
|
||||||
@@ -31,7 +32,7 @@ export function TimezoneAutocomplete({
|
|||||||
zones,
|
zones,
|
||||||
getTimezoneOffset,
|
getTimezoneOffset,
|
||||||
showIcon = false,
|
showIcon = false,
|
||||||
autoFocus = false,
|
inputRef,
|
||||||
width,
|
width,
|
||||||
size = "small",
|
size = "small",
|
||||||
placeholder = "Select timezone",
|
placeholder = "Select timezone",
|
||||||
@@ -40,6 +41,7 @@ export function TimezoneAutocomplete({
|
|||||||
onClose,
|
onClose,
|
||||||
disableClearable = false,
|
disableClearable = false,
|
||||||
hideBorder = false,
|
hideBorder = false,
|
||||||
|
openOnFocus = false,
|
||||||
}: TimezoneAutocompleteProps) {
|
}: TimezoneAutocompleteProps) {
|
||||||
const options = useMemo<TimezoneOption[]>(() => {
|
const options = useMemo<TimezoneOption[]>(() => {
|
||||||
return zones.map((tz) => ({
|
return zones.map((tz) => ({
|
||||||
@@ -53,7 +55,7 @@ export function TimezoneAutocomplete({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
autoFocus={autoFocus}
|
openOnFocus={openOnFocus}
|
||||||
value={selectedOption}
|
value={selectedOption}
|
||||||
onChange={(event, newValue) => {
|
onChange={(event, newValue) => {
|
||||||
if (newValue) {
|
if (newValue) {
|
||||||
@@ -72,6 +74,7 @@ export function TimezoneAutocomplete({
|
|||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
|
inputRef={inputRef}
|
||||||
sx={
|
sx={
|
||||||
hideBorder
|
hideBorder
|
||||||
? {
|
? {
|
||||||
|
|||||||
Reference in New Issue
Block a user