From 9b420232a33dc523b892abf1c75f74a5268ecb1f Mon Sep 17 00:00:00 2001 From: Astrian Zheng Date: Wed, 19 Feb 2025 22:32:26 +1100 Subject: [PATCH] fix: update SingleDatePicker to use onClose prop for closing functionality and improve accessibility --- playground/app.tsx | 2 +- src/components/SingleDatePicker.tsx | 16 ++++++---------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/playground/app.tsx b/playground/app.tsx index eb83d8c..c26d28d 100644 --- a/playground/app.tsx +++ b/playground/app.tsx @@ -19,7 +19,7 @@ export default () => { }} onSelect={onSelect} localization="zh-CN" - closable + onClose={() => alert('close')} /> ) diff --git a/src/components/SingleDatePicker.tsx b/src/components/SingleDatePicker.tsx index 2486fbd..8a11b0e 100644 --- a/src/components/SingleDatePicker.tsx +++ b/src/components/SingleDatePicker.tsx @@ -34,15 +34,11 @@ interface Props { /** * User requires to close the panel without select a specific date. Note that the close button is not - * visible, but can be read by screen reader. + * visible, but can be read by screen reader. The close button for the screen reader is only available + * when this prop is not `undefined`. + * @default undefined */ onClose?: () => void - - /** - * Show a close button to the users with screen reader. - * @default false - */ - closable?: boolean } /** @@ -52,7 +48,7 @@ interface Props { * * @param {Props} props */ -export default ({ value, onSelect, localization, onClose, closable = false }: Props) => { +export default ({ value, onSelect, localization, onClose }: Props) => { const [currentMonth, setCurrentMonth] = useState(new Date().getMonth()) const [currentYear, setCurrentYear] = useState(new Date().getFullYear()) const [selectedDate, setSelectedDate] = useState(new Date()) @@ -127,7 +123,7 @@ export default ({ value, onSelect, localization, onClose, closable = false }: Pr {new Date(currentYear, index).toLocaleString(localization || navigator.language, { month: 'long' })} )} - { closable && } + { !!onClose && } ) else return ( @@ -154,7 +150,7 @@ export default ({ value, onSelect, localization, onClose, closable = false }: Pr {date.toDateString() === new Date().toDateString() && } )} - { closable && } + { !!onClose && } ) } \ No newline at end of file