Skip to content

Commit 6d78c21

Browse files
Merge pull request Hacker0x01#159 from croscon/feature-popover-anywhere
Control popover location
2 parents bdaced0 + 879db1e commit 6d78c21

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/datepicker.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ var DatePicker = React.createClass( {
1212
weekdays: React.PropTypes.arrayOf( React.PropTypes.string ),
1313
locale: React.PropTypes.string,
1414
dateFormatCalendar: React.PropTypes.string,
15+
popoverAttachment: React.PropTypes.string,
16+
popoverTargetAttachment: React.PropTypes.string,
17+
popoverTargetOffset: React.PropTypes.string,
1518
onChange: React.PropTypes.func.isRequired,
1619
onBlur: React.PropTypes.func
1720
},
@@ -110,7 +113,11 @@ var DatePicker = React.createClass( {
110113
calendar: function() {
111114
if ( this.state.focus ) {
112115
return (
113-
<Popover>
116+
<Popover
117+
attachment={this.props.popoverAttachment}
118+
targetAttachment={this.props.popoverTargetAttachment}
119+
targetOffset={this.props.popoverTargetOffset}>
120+
114121
<Calendar
115122
weekdays={this.props.weekdays}
116123
locale={this.props.locale}

src/popover.jsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@ var React = require( "react" );
33
var Popover = React.createClass( {
44
displayName: "Popover",
55

6+
propTypes: {
7+
attachment: React.PropTypes.string,
8+
targetAttachment: React.PropTypes.string,
9+
targetOffset: React.PropTypes.string
10+
},
11+
12+
getDefaultProps: function() {
13+
return {
14+
attachment: "top left",
15+
targetAttachment: "bottom left",
16+
targetOffset: "10px 0"
17+
};
18+
},
19+
620
componentWillMount: function() {
721
var popoverContainer = document.createElement( "span" );
822
popoverContainer.className = "datepicker__container";
@@ -32,10 +46,10 @@ var Popover = React.createClass( {
3246
_tetherOptions: function() {
3347
return {
3448
element: this._popoverElement,
35-
target: this.getDOMNode().parentElement,
36-
attachment: "top left",
37-
targetAttachment: "bottom left",
38-
targetOffset: "10px 0",
49+
target: this.getDOMNode().parentElement.querySelector( "input" ),
50+
attachment: this.props.attachment,
51+
targetAttachment: this.props.targetAttachment,
52+
targetOffset: this.props.targetOffset,
3953
optimizations: {
4054
moveElement: false // always moves to <body> anyway!
4155
},

0 commit comments

Comments
 (0)