Allow Datepicker to be empty
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 42/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- react, typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Bắt đầu từ component Datepicker và kiểm tra cách nút Clear, defaultDate và onSelectedDateChanged hiện đang xử lý các giá trị. So sánh hành vi hiện tại với trạng thái null hoặc rỗng được yêu cầu, sau đó xác minh rằng việc xóa một ngày tùy chọn tạo ra giá trị mong đợi mà không làm ảnh hưởng đến hành vi của defaultDate hoặc minDate.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
Datepicker only allows to receive a valid Date but it would be really great if we could set null, "" or any kind of value that represents empty.
Context
So, i was working in specific use case where users can set a Date but this field is optional (null under the hood), so the user can also keep it empty.
When i start this i saw Clear button and i tought this was exactly what i was looking for but then i realize that this button only resets the field to defaultDate or minDate but never to "" (as native input does) or null. Since Clear button resets to defaultDate, would be great if defaultDate accepts null or even if onSeletedDateChanged could receive the current value and a second boolean prop like isClearAction so we can customize the logic.
For now, since im using React Hook Form to deal with validations, i've reached this by using the following approach:
type MyDatepickerProps = Omit<
DatepickerProps,
'showClearButton' | 'labelClearButton'
> & {
onClear?: () => void;
};
const MyDatepicker = forwardRef<
DatepickerRef,
MyDatepickerDatepickerProps
>(({ onClear, ...rest }, ref) => {
return (
<div>
<Datepicker
ref={ref}
{...rest}
showClearButton={!onClear}
labelClearButton="Reset"
/>
{onClear && (
<button
onClick={onClear}
type="button"
>
{/* This is just a X icon for the button */}
<HiXCircle />
</button>
)}
</div>
);
});
And in the form (remember: im using React Hook Form):
<Controller
control={control}
name="my-field"
render={({ field }) => (
<MyDatepicker
minDate={new Date()}
value={field.value === null ? '' : field.value?.toDateString()}
placeholder="Date"
onSelectedDateChanged={field.onChange}
onClear={() => field.onChange(null)}
/>
)}
/>;
As you can see, im not using default onChange since it not triggers with current value. Thats why im using Controller to customize field actions.
Would be very very good to have this behavior on this component 🥺
EDIT: I've already read some issues about that but this is a feature request since it is not implemented.
- Ngôn ngữ chính
- TypeScript
- Star
- 2.1k
- Fork
- 502
- Merge trung bình
- 19 giờ 16 phút
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của themesberg/flowbite-react
-
fix(Carousel): can't give dynamic children to CarouselCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở:bug: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
themesberg/flowbite-react#1469 · 1 bình luận ·
-
Pagination is broken if there is only one pageCó thể đã có người làm @Mukilan1600 đã nhận 1019 ngày trước. Đang mở:bug: bug confirmed good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
themesberg/flowbite-react#1048 · 7 bình luận · 1 reaction ·
-
:books: documentation help wanted
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
themesberg/flowbite-react#1696 · 2 bình luận ·
-
Add a QRCode componentĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
themesberg/flowbite-react#1693 ·
-
NavbarCollapse closes when toggling a MegaMenuDropdown on mobileCó thể làm lại được @sarthak-11231 đã nhận 43 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 58/100
themesberg/flowbite-react#1686 · 2 bình luận ·
Tất cả issue của themesberg/flowbite-react
Issue tương tự
-
Add: Upin & Ipin Channel HDĐang mởcheck:passed streams:add
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
S: triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
iot client
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Open-Locker/Open-Locker#365 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 69/100
inmanta/web-console#7787 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
shoelace-style/webawesome#2979 ·
Maintainer thường phản hồi trong vòng 1 ngày