Skip to content

Commit a7aa195

Browse files
committed
add props to pass an input ID and input name to the input field
1 parent cc18f59 commit a7aa195

File tree

5 files changed

+44
-17
lines changed

5 files changed

+44
-17
lines changed

CONTRIBUTING.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
# Contributing
22

3-
Thanks for your interest in contributing to `react-tailwindcss-datepicker`! Please take a moment to review this document **before submitting a pull request**.
3+
Thanks for your interest in contributing to `react-tailwindcss-datepicker`! Please take a moment to
4+
review this document **before submitting a pull request**.
45

5-
- [Pull requests](#pull-requests)
6-
- [Installation](#installation)
7-
- [Coding standards](#coding-standards)
8-
- [Running playground](#running-playgrounds)
9-
- [Before you make a Pull Request](#before-you-make-a-pull-request)
6+
- [Pull requests](#pull-requests)
7+
- [Installation](#installation)
8+
- [Coding standards](#coding-standards)
9+
- [Running playground](#running-playgrounds)
10+
- [Before you make a Pull Request](#before-you-make-a-pull-request)
1011

1112
## Pull requests
1213

1314
**Please ask first before starting work on any significant new features.**
1415

15-
It's never a fun experience to have your pull request declined after investing a lot of time and effort into a new feature. To avoid this from happening, we request that contributors create [an issue](https://github.com/onesine/react-tailwindcss-datepicker/issues) to first discuss any significant new features.
16+
It's never a fun experience to have your pull request declined after investing a lot of time and
17+
effort into a new feature. To avoid this from happening, we request that contributors create
18+
[an issue](https://github.com/onesine/react-tailwindcss-datepicker/issues) to first discuss any
19+
significant new features.
1620

1721
## Installation
1822

@@ -24,8 +28,8 @@ yarn install
2428

2529
## Coding standards
2630

27-
We use `prettier` for making sure that the codebase is formatted consistently.
28-
To automatically fix any style violations in your code, you can run:
31+
We use `prettier` for making sure that the codebase is formatted consistently. To automatically fix
32+
any style violations in your code, you can run:
2933

3034
**Using yarn**
3135

@@ -61,16 +65,18 @@ npm dev
6165

6266
## Before you make a Pull Request
6367

64-
We recommend to run these scripts in sequence before you make your commit message amd open a Pull Request
68+
We recommend to run these scripts in sequence before you make your commit message amd open a Pull
69+
Request
6570

6671
**Let's clean the code first**
72+
6773
```sh
6874
yarn pret:fix
6975
```
7076

7177
**Test a build of your changes**
78+
7279
```sh
7380
yarn build
7481

7582
```
76-

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,8 @@
6565
"tailwindcss": "^3.2.4",
6666
"tslib": "^2.4.0",
6767
"typescript": "^4.8.4"
68+
},
69+
"publishConfig": {
70+
"registry": "https://registry.npmjs.com"
6871
}
6972
}

src/components/Datepicker.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ interface Props {
4040
i18n?: string;
4141
disabled?: boolean;
4242
inputClassName?: string | null;
43+
inputId?: string;
44+
inputName?: string;
4345
containerClassName?: string | null;
4446
displayFormat?: string;
4547
readOnly?: boolean;
@@ -68,7 +70,9 @@ const Datepicker: React.FC<Props> = ({
6870
readOnly = false,
6971
minDate = null,
7072
maxDate = null,
71-
disabledDates = null
73+
disabledDates = null,
74+
inputId,
75+
inputName
7276
}) => {
7377
// Ref
7478
const containerRef = useRef<HTMLDivElement>(null);
@@ -281,7 +285,9 @@ const Datepicker: React.FC<Props> = ({
281285
displayFormat,
282286
minDate,
283287
maxDate,
284-
disabledDates
288+
disabledDates,
289+
inputId,
290+
inputName
285291
};
286292
}, [
287293
asSingle,
@@ -305,7 +311,9 @@ const Datepicker: React.FC<Props> = ({
305311
firstGotoDate,
306312
minDate,
307313
maxDate,
308-
disabledDates
314+
disabledDates,
315+
inputId,
316+
inputName
309317
]);
310318

311319
return (

src/components/Input.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ const Input: React.FC = () => {
2626
disabled,
2727
inputClassName,
2828
readOnly,
29-
displayFormat
29+
displayFormat,
30+
inputId,
31+
inputName
3032
} = useContext(DatepickerContext);
3133

3234
// UseRefs
@@ -177,14 +179,18 @@ const Input: React.FC = () => {
177179
: `${displayFormat}${asSingle ? "" : ` ${separator} ${displayFormat}`}`
178180
}
179181
value={inputText}
182+
id={inputId}
183+
name={inputName}
184+
autoComplete="off"
185+
role="presentation"
180186
onChange={handleInputChange}
181187
/>
182188

183189
<button
184190
type="button"
185191
ref={buttonRef}
186192
disabled={disabled}
187-
className="absolute right-0 h-full px-3 text-gray-400 focus:outline-none disabled:opacity-40 disabled:cursor-not-allowed"
193+
className="absolute top-0 right-0 h-full px-3 text-gray-400 focus:outline-none disabled:opacity-40 disabled:cursor-not-allowed"
188194
>
189195
{inputText ? <CloseIcon className="h-5 w-5" /> : <DateIcon className="h-5 w-5" />}
190196
</button>

src/contexts/DatepickerContext.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ interface DatepickerStore {
3131
minDate?: DateType | null;
3232
maxDate?: DateType | null;
3333
disabledDates?: DateRangeType[] | null;
34+
inputId?: string;
35+
inputName?: string;
3436
}
3537

3638
const DatepickerContext = createContext<DatepickerStore>({
@@ -62,7 +64,9 @@ const DatepickerContext = createContext<DatepickerStore>({
6264
displayFormat: "YYYY-MM-DD",
6365
minDate: null,
6466
maxDate: null,
65-
disabledDates: null
67+
disabledDates: null,
68+
inputId: undefined,
69+
inputName: undefined
6670
});
6771

6872
export default DatepickerContext;

0 commit comments

Comments
 (0)