Skip to content

Commit a7f37e6

Browse files
authored
fix: disable trigger popover on click for datepicker (#927)
1 parent 7e71f0f commit a7f37e6

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/DatePicker/DatePicker.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,11 @@ class DatePicker extends Component {
200200
});
201201
}
202202

203-
handleClick = () => {
203+
handleClickButton = () => {
204204
this.setState({ isExpanded: !this.state.isExpanded });
205+
206+
const popover = this.popoverRef && this.popoverRef.current;
207+
popover && popover.triggerBody();
205208
};
206209

207210
handleOutsideClickAndEscape = () => {
@@ -337,7 +340,6 @@ class DatePicker extends Component {
337340
compact={compact}
338341
disableStyles={disableStyles}
339342
disabled={disabled}
340-
onClick={this.handleClick}
341343
validationState={!this.state.isExpanded ? validationState : null} >
342344
<FormInput
343345
{...inputProps}
@@ -355,12 +357,14 @@ class DatePicker extends Component {
355357
disableStyles={disableStyles}
356358
disabled={disableButton}
357359
glyph='calendar'
360+
onClick={this.handleClickButton}
358361
option='transparent' />
359362
</InputGroup.Addon>
360363
</InputGroup>
361364
}
362365
disableKeyPressHandler
363366
disableStyles={disableStyles}
367+
disableTriggerOnClick
364368
disabled={disableButton}
365369
noArrow
366370
onClickOutside={this.handleOutsideClickAndEscape}

src/Popover/Popover.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class Popover extends Component {
9494
disableEdgeDetection,
9595
disableKeyPressHandler,
9696
disableStyles,
97+
disableTriggerOnClick,
9798
onClickOutside,
9899
onEscapeKey,
99100
disabled,
@@ -110,9 +111,13 @@ class Popover extends Component {
110111
...rest
111112
} = this.props;
112113

113-
let onClickFunctions = this.triggerBody;
114-
if (control.props.onClick) {
115-
onClickFunctions = chain(this.triggerBody, control.props.onClick);
114+
let onClickFunctions;
115+
if (!disableTriggerOnClick) {
116+
onClickFunctions = this.triggerBody;
117+
118+
if (control.props.onClick) {
119+
onClickFunctions = chain(this.triggerBody, control.props.onClick);
120+
}
116121
}
117122

118123
const id = popperProps.id || this.popoverId;
@@ -180,6 +185,7 @@ Popover.propTypes = {
180185
disableEdgeDetection: PropTypes.bool,
181186
disableKeyPressHandler: PropTypes.bool,
182187
disableStyles: PropTypes.bool,
188+
disableTriggerOnClick: PropTypes.bool,
183189
noArrow: PropTypes.bool,
184190
placement: PropTypes.oneOf(POPPER_PLACEMENTS),
185191
popperClassName: PropTypes.string,
@@ -203,6 +209,7 @@ Popover.propDescriptions = {
203209
control: 'Node to render as the reference element (that the `body` will be placed in relation to).',
204210
disableEdgeDetection: 'Set to **true** to render popover without edge detection so popover will not flip from top to bottom with scroll.',
205211
disableKeyPressHandler: 'Set to **true** to remove onKeyPress handler and aria-* roles. Only do so if the control is a complex component such as a FormInput with Button.',
212+
disableTriggerOnClick: 'Set to **true** to remove default triggerBody handler used in onClick. Useful for when a custom method is desired to open the Popover.',
206213
noArrow: 'Set to **true** to render a popover without an arrow.',
207214
placement: 'Initial position of the `body` (overlay) related to the `control`.',
208215
popperClassName: 'Additional classeNames to be spread to the overlay element.',

0 commit comments

Comments
 (0)