Skip to content

feat: Add support for inputTabIndex prop #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@ export default function Playground() {
const [startWeekOn, setStartWeekOn] = useState<WeekStringType>("mon");
const [required, setRequired] = useState(false);
const [popoverDirection, setPopoverDirection] = useState<PopoverDirectionType>("down");
const [tabIndex, setTabIndex] = useState<number | undefined>(undefined);

return (
<div className="px-4 py-8">
@@ -114,6 +115,7 @@ export default function Playground() {
i18n={i18n}
disabled={disabled}
inputClassName={inputClassName}
inputTabIndex={tabIndex}
containerClassName={containerClassName}
toggleClassName={toggleClassName}
displayFormat={displayFormat}
@@ -244,6 +246,23 @@ export default function Playground() {
</label>
</div>
</div>
<div className="mb-2 w-1/2 sm:w-full">
<div className="inline-flex items-center">
<input
type="number"
className="mr-2 w-24 rounded"
id="tabIndex"
value={tabIndex}
onChange={function (e) {
console.log(e.target.value, parseInt(e.target.value));
return setTabIndex(parseInt(e.target.value));
}}
/>
<label className="block" htmlFor="required">
Tab Index
</label>
</div>
</div>
</div>

<div className="w-full sm:w-1/3 pr-2 flex flex-col">
3 changes: 3 additions & 0 deletions src/components/Datepicker.tsx
Original file line number Diff line number Diff line change
@@ -50,6 +50,7 @@ const Datepicker = (props: DatepickerType) => {
inputClassName = null,
inputId,
inputName,
inputTabIndex,

minDate = undefined,
maxDate = undefined,
@@ -318,6 +319,7 @@ const Datepicker = (props: DatepickerType) => {
inputId,
inputName,
inputText,
inputTabIndex,
maxDate,
minDate,
onChange,
@@ -351,6 +353,7 @@ const Datepicker = (props: DatepickerType) => {
value,
disabled,
inputClassName,
inputTabIndex,
containerClassName,
toggleClassName,
toggleIcon,
12 changes: 12 additions & 0 deletions src/components/Input.tsx
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@ const Input = (e: Props) => {
separator,
disabled,
inputClassName,
inputTabIndex,
toggleClassName,
toggleIcon,
readOnly,
@@ -173,6 +174,15 @@ const Input = (e: Props) => {
: defaultToggleClassName;
}, [toggleClassName, buttonRef, classNames]);

const handleOnBlur = useCallback(() => {
const input = inputRef.current;
if (input) {
if (input.tabIndex !== undefined) {
hideDatepicker();
}
}
}, [inputTabIndex]);

// UseEffects && UseLayoutEffect
useEffect(() => {
if (inputRef && e.setContextRef && typeof e.setContextRef === "function") {
@@ -282,6 +292,7 @@ const Input = (e: Props) => {
ref={inputRef}
type="text"
className={getClassName()}
tabIndex={inputTabIndex}
disabled={disabled}
readOnly={readOnly}
required={required}
@@ -297,6 +308,7 @@ const Input = (e: Props) => {
role="presentation"
onChange={handleInputChange}
onKeyDown={handleInputKeyDown}
onBlur={handleOnBlur}
/>

<button
2 changes: 2 additions & 0 deletions src/contexts/DatepickerContext.ts
Original file line number Diff line number Diff line change
@@ -48,6 +48,7 @@ interface DatepickerStore {
inputId?: string;
inputName?: string;
inputText: string;
inputTabIndex?: number;

maxDate?: DateType | null;
minDate?: DateType | null;
@@ -97,6 +98,7 @@ const DatepickerContext = createContext<DatepickerStore>({

input: undefined,
inputClassName: "",
inputTabIndex: undefined,

inputId: undefined,
inputName: undefined,
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -83,6 +83,7 @@ export interface DatepickerType {
toggleIcon?: (open: boolean) => ReactNode;
inputId?: string;
inputName?: string;
inputTabIndex?: number;
displayFormat?: string;
readOnly?: boolean;
minDate?: DateType;