Allow Datepicker to be empty
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 42/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- react, typescript
- 领域
- frontend
调研方向
从 Datepicker 组件开始,检查 Clear 按钮、defaultDate 和 onSelectedDateChanged 当前如何处理值。将现有行为与所要求的 null 或空状态进行比较,然后验证清除可选日期是否会产生预期值,同时不会破坏 defaultDate 或 minDate 的行为。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- TypeScript
- 星标
- 2.2k
- 派生
- 504
- 平均合并
- 19 小时 16 分钟
- 30 天内合并 PR
- 2
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
themesberg/flowbite-react 的其他 Issue
-
fix(Carousel): can't give dynamic children to Carousel可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭:bug: bug
难度 2/5 1-3 小时 新手友好度 62/100
themesberg/flowbite-react#1469 · 1 条评论 ·
-
Pagination is broken if there is only one page可能已有人在做 @Mukilan1600 于 1021 天前认领。 未关闭:bug: bug confirmed good first issue
难度 2/5 1-3 小时 新手友好度 65/100
themesberg/flowbite-react#1048 · 7 条评论 · 1 个 reaction ·
-
:books: documentation help wanted
难度 5/5 一周以上 新手友好度 35/100
themesberg/flowbite-react#1696 · 2 条评论 ·
-
难度 5/5 一周以上 新手友好度 15/100
themesberg/flowbite-react#1693 ·
-
NavbarCollapse closes when toggling a MegaMenuDropdown on mobile可能重新可做 @sarthak-11231 于 45 天前认领,目前没有进行中的 PR。 未关闭
难度 3/5 1-2 天 新手友好度 58/100
themesberg/flowbite-react#1686 · 2 条评论 ·
查看 themesberg/flowbite-react 的全部 Issue
相似的 Issue
-
check:passed streams:add
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 1 天内回复
-
bug implicit-state
难度 2/5 1-3 小时 新手友好度 76/100
-
book-layout.spec fails when the similar-books rail holds other projects' books可能已有人在做 @praetorianer777 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
praetorianer777/GoTome#373 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
Tencent/tdesign-react#4465 · 1 条评论 ·
维护者通常 1 天内回复
-
area:cards enhancement ready-for-agent
难度 2/5 1-3 小时 新手友好度 66/100
fil-donadoni/tolaria#8883 ·
维护者通常 1 天内回复