-
Hi folks! I have a tricky setup where I need to delicately manage focus, and it seems like there's no way to disable the internal focus handling of react-day-picker. My setup is a grid (AG Grid specifically), where the cells in the grid are focused, and when a cell lose focus in the DOM, editing stops. I can show a date picker just fine, but when I click a date, the internal focus management in react-day-picker wants to focus the date I just clicked, causing the grid cell to lose focus, and editing of the grid to stop. I tried adding a react-day-picker/src/DayPicker.tsx Line 170 in ae63d4c Is there a way to somehow cause react-day-picker to not change focus when clicking a date? Or to disable the focus management entirely? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
@augustl sure it should be possible. I can provide an example later. Try with a custom |
Beta Was this translation helpful? Give feedback.
-
I'm not sure if I understand your requirement :) Are you trying to keep a grid cell focused, while allowing the user to pick a day? If so, I'd leave the focus go where the browser wants (or DayPicker decides). Try to see if the <DayPicker onSelect={ () => putFocusBack() } /> Otherwise, try to identify in the DayPicker code where exactly the focus is lost: day buttons in DayPicker are focusable and the browser - not DayPicker - may change the focus too. If it is the https://stackblitz.com/edit/react-day-picker-9-2332?file=src%2FApp.tsx import './App.css';
import 'react-day-picker/style.css';
import { DayButtonProps, DayPicker, useDayPicker } from 'react-day-picker';
function DayButton(props: DayButtonProps) {
const { day, modifiers, ...buttonProps } = props;
const dayPicker = useDayPicker();
return (
<button
{...buttonProps}
onClick={(e) => dayPicker.select?.(day.date, modifiers, e)}
onFocus={undefined}
onBlur={undefined}
/>
);
}
function App() {
return (
<DayPicker
mode="single"
components={{
DayButton,
}}
/>
);
}
export default App; |
Beta Was this translation helpful? Give feedback.
I'm not sure if I understand your requirement :) Are you trying to keep a grid cell focused, while allowing the user to pick a day?
If so, I'd leave the focus go where the browser wants (or DayPicker decides). Try to see if the
onSelect
handler can help you to move the focus to the initial cell after a day is picked up.Otherwise, try to identify in the DayPicker code where exactly the focus is lost: day buttons in DayPicker are focusable and the browser - not DayPicker - may change the focus too.
If it is the
handleDayClick
handler, then you can…