-
|
When using a custom DayContent component via the components prop in v9, click events on day buttons are not registered. The custom content renders correctly, but clicking on days does not trigger onSelect. Environmentreact-day-picker version: 9.13.0 import { DayPicker } from 'react-day-picker';
import 'react-day-picker/style.css';
function CustomDayContent({ date }) {
return (
<div>
<span>{date.getDate()}</span>
<span style={{ fontSize: '10px' }}>$100</span>
</div>
);
}
function Calendar() {
const [selected, setSelected] = useState();
return (
<DayPicker
mode="range"
selected={selected}
onSelect={setSelected}
components={{
DayContent: CustomDayContent,
}}
/>
);
}Expected BehaviorClicking on a day should trigger onSelect and select the date, even when using a custom DayContent component. Actual BehaviorClicking on days does nothing. The onSelect callback is never called. If I remove the custom DayContent component, clicks work as expected. WorkaroundCurrently downgraded to v8.10.1 where this works correctly with the same pattern. Additional ContextThe issue appears to be that the custom content wrapper inside DayContent is intercepting pointer events meant for the underlying element. Adding pointer-events: none to the custom wrapper div resolves the issue but feels like a workaround rather than expected behavior. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Thanks for the report @dotio In v9 the Recommended options in v9:
Example: import { DayButton, type DayButtonProps, DayPicker } from "react-day-picker";
function CustomDayButton(props: DayButtonProps) {
const { day, modifiers, ...buttonProps } = props;
return (
<DayButton day={day} modifiers={modifiers} {...buttonProps}>
<div>
<span>{day.date.getDate()}</span>
<span style={{ fontSize: "10px" }}>$100</span>
</div>
</DayButton>
);
}
<DayPicker components={{ DayButton: CustomDayButton }} />This keeps the built-in click handlers and accessibility intact. Please give a look to the upgrade guide and custom components guide. |
Beta Was this translation helpful? Give feedback.
Thanks for the report @dotio
In v9 the
DayContentcomponent was removed, so passingcomponents={{ DayContent: ... }}doesn’t hook into the day button anymore. The clickable area andonSelectare handled byDayButton, so if custom content sits outside that button (or overlays it), clicks won’t reach the handler. This whypointer-events: noneappears to “fix” it.Recommended options in v9:
formatDayformatter.DayButtonand render your custom content inside it while forwarding all props (important).Example: