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

Add position prop #791

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -56,6 +56,7 @@ Below we have all the props that we can use with the `<DateTime>` component. The
| **dateFormat** | `boolean` or `string` | `true` | Defines the format for the date. It accepts any [Moment.js date format](http://momentjs.com/docs/#/displaying/format/) (not in localized format). If `true` the date will be displayed using the defaults for the current locale. If `false` the datepicker is disabled and the component can be used as timepicker, see [available units docs](#specify-available-units). |
| **timeFormat** | `boolean` or `string` | `true` | Defines the format for the time. It accepts any [Moment.js time format](http://momentjs.com/docs/#/displaying/format/) (not in localized format). If `true` the time will be displayed using the defaults for the current locale. If `false` the timepicker is disabled and the component can be used as datepicker, see [available units docs](#specify-available-units). |
| **input** | `boolean` | `true` | Whether to show an input field to edit the date manually. |
| **position** | `string` | `down` | Whether to show the picker above or below the input feild. `up` to show above the input feild. |
| **open** | `boolean` | `null` | Whether to open or close the picker. If not set react-datetime will open the datepicker on input focus and close it on click outside. |
| **locale** | `string` | `null` | Manually set the locale for the react-datetime instance. Moment.js locale needs to be loaded to be used, see [i18n docs](#i18n).
| **utc** | `boolean` | `false` | When true, input time values will be interpreted as UTC (Zulu time) by Moment.js. Otherwise they will default to the user's local timezone.
Expand Down
4 changes: 4 additions & 0 deletions css/react-datetime.css
Expand Up @@ -16,6 +16,10 @@
box-shadow: 0 1px 3px rgba(0,0,0,.1);
border: 1px solid #f9f9f9;
}
.rdtUp{
position: absolute;
top: -306px;
}
Comment on lines +19 to +22
Copy link

@IndrekV IndrekV May 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this 1 style to rdtPicker would fix the open in top problem reliably. Meaning that the popup will always be in the correct place no matter if in calendar or time view which have different heights. The static -306px top position would only work for one of the views.

.rdtPicker {
  bottom: 100%;
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok maybe this can solve the problem of going out of the screen, if anyone want the datepicker above the input field, this prop can be helpful, a little refraction may be needed.

.rdtOpen .rdtPicker {
display: block;
}
Expand Down
12 changes: 11 additions & 1 deletion src/DateTime.js
Expand Up @@ -89,13 +89,23 @@ export default class Datetime extends React.Component {
return (
<ClickableWrapper className={ this.getClassName() } onClickOut={ this._handleClickOutside }>
{ this.renderInput() }
<div className="rdtPicker">
<div className={this.getClassNames()}>
{ this.renderView() }
</div>
</ClickableWrapper>
);
}

getClassNames() {
let defaultClassName='rdtPicker';
if (this.props.position) {
const mPosition=this.props.position.toLowerCase();
if (mPosition==='up') return defaultClassName+' rdtUp';
return defaultClassName;
}
return defaultClassName;
}

renderInput() {
if ( !this.props.input ) return;

Expand Down
4 changes: 2 additions & 2 deletions src/playground/App.js
Expand Up @@ -14,8 +14,8 @@ class App extends React.Component {

render() {
return (
<div>
<Datetime />
<div style={{marginTop:'48vh'}}>
<Datetime position='up' />
</div>
);
}
Expand Down