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

[datetime2] feat(DateRangeInput2): remove target wrapper element #5474

Merged
merged 3 commits into from
Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/datetime2/src/common/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ export const DATE_INPUT = `${NS}-date-input`;
export const DATE_INPUT_POPOVER = `${NS}-date-input-popover`;
export const DATE_INPUT_TIMEZONE_SELECT = `${NS}-date-input-timezone-select`;

export const DATE_RANGE_INPUT = `${NS}-date-range-input`;
export const DATE_RANGE_INPUT_POPOVER = `${NS}-date-range-input-popover`;

export const TIMEZONE_SELECT = `${NS}-timezone-select`;
export const TIMEZONE_SELECT_POPOVER = `${TIMEZONE_SELECT}-popover`;
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import * as React from "react";
import {
AbstractPureComponent2,
Boundary,
Classes,
Classes as CoreClasses,
DISPLAYNAME_PREFIX,
InputGroup,
InputGroupProps2,
Expand All @@ -39,9 +39,9 @@ import {
DateRangePicker,
DateRangeShortcut,
} from "@blueprintjs/datetime";
import { Popover2, Popover2Props } from "@blueprintjs/popover2";
import { Popover2, Popover2Props, Popover2TargetProps } from "@blueprintjs/popover2";

import { DateRange, NonNullDateRange } from "../../common/dateRange";
import { Classes, DateRange, NonNullDateRange } from "../../common";
import { isDayInRange, isSameTime } from "../../common/dateUtils";
import * as Errors from "../../common/errors";

Expand Down Expand Up @@ -354,26 +354,21 @@ export class DateRangeInput2 extends AbstractPureComponent2<DateRangeInput2Props
/>
);

const popoverClassName = classNames(popoverProps.className, this.props.className);

// allow custom props for the popover and each input group, but pass them in an order that
// guarantees only some props are overridable.
return (
<Popover2
isOpen={this.state.isOpen}
placement="bottom-start"
{...this.props.popoverProps}
{...popoverProps}
autoFocus={false}
className={popoverClassName}
className={classNames(Classes.DATE_RANGE_INPUT, popoverProps.className, this.props.className)}
content={popoverContent}
enforceFocus={false}
onClose={this.handlePopoverClose}
>
<div className={Classes.CONTROL_GROUP}>
{this.renderInputGroup(Boundary.START)}
{this.renderInputGroup(Boundary.END)}
</div>
</Popover2>
popoverClassName={classNames(Classes.DATE_RANGE_INPUT_POPOVER, popoverProps.popoverClassName)}
renderTarget={this.renderTarget}
/>
);
}

Expand All @@ -385,6 +380,18 @@ export class DateRangeInput2 extends AbstractPureComponent2<DateRangeInput2Props
}
}

// We use the renderTarget API to flatten the rendered DOM.
private renderTarget =
// N.B. pull out `isOpen` so that it's not forwarded to the DOM.
({ isOpen, ...targetProps }: Popover2TargetProps & React.HTMLProps<HTMLDivElement>) => {
return (
<div {...targetProps} className={classNames(CoreClasses.CONTROL_GROUP, targetProps.className)}>
{this.renderInputGroup(Boundary.START)}
{this.renderInputGroup(Boundary.END)}
</div>
);
};

private renderInputGroup = (boundary: Boundary) => {
const inputProps = this.getInputProps(boundary);
const handleInputEvent = boundary === Boundary.START ? this.handleStartInputEvent : this.handleEndInputEvent;
Expand Down