Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datepicker v3 #70

Merged
merged 10 commits into from
Oct 6, 2020
2 changes: 1 addition & 1 deletion src/datepicker/DatePicker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createOnKeyDown } from "reakit-utils";
import { createOnKeyDown, isSelfTarget } from "reakit-utils";
navin-moorthy marked this conversation as resolved.
Show resolved Hide resolved
import { BoxHTMLProps, BoxOptions, useBox } from "reakit";
import { createComponent, createHook } from "reakit-system";
import { ariaAttr, callAllHandlers } from "@chakra-ui/utils";
Expand Down
13 changes: 11 additions & 2 deletions src/datepicker/DatePickerContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { PopoverHTMLProps, PopoverOptions, usePopover } from "reakit";

import { DATE_PICKER_CONTENT_KEYS } from "./__keys";
import { DatePickerStateReturn } from "./DatePickerState";
import { callAllHandlers } from "@chakra-ui/utils";

export type DatePickerContentOptions = PopoverOptions &
Pick<DatePickerStateReturn, "dialogId">;
Expand All @@ -20,8 +21,16 @@ export const useDatePickerContent = createHook<
compose: usePopover,
keys: DATE_PICKER_CONTENT_KEYS,

useProps({ dialogId }, htmlProps) {
return { id: dialogId, ...htmlProps };
useProps({ dialogId }, { onMouseDown: htmlOnMouseDown, ...htmlProps }) {
const onMouseDown = (e: React.MouseEvent) => {
e.stopPropagation();
};

return {
id: dialogId,
onMouseDown: callAllHandlers(htmlOnMouseDown, onMouseDown),
...htmlProps,
};
},
});

Expand Down
4 changes: 0 additions & 4 deletions src/datepicker/DatePickerState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ export const useDatePickerState = (props: DatePickerStateInitialProps = {}) => {
calendar.setFocused(true);
dateValue && calendar.focusCell(dateValue);
}

if (!popover.visible) {
composite.first();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [popover.visible]);

Expand Down
13 changes: 11 additions & 2 deletions src/datepicker/DatePickerTrigger.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { callAllHandlers } from "@chakra-ui/utils";
import { createComponent, createHook } from "reakit-system";
import {
usePopoverDisclosure,
Expand All @@ -22,8 +23,16 @@ export const useDatePickerTrigger = createHook<
compose: usePopoverDisclosure,
keys: DATE_PICKER_TRIGGER_KEYS,

useProps(_, htmlProps) {
return { tabIndex: -1, ...htmlProps };
useProps(_, { onMouseDown: htmlOnMouseDown, ...htmlProps }) {
const onMouseDown = (e: React.MouseEvent) => {
e.stopPropagation();
};

return {
tabIndex: -1,
onMouseDown: callAllHandlers(htmlOnMouseDown, onMouseDown),
...htmlProps,
};
},
});

Expand Down