mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-09 10:50:24 +00:00
[share dialog] expiration time: improved 'date-and-time-picker' (#4613)
* changed it to 'click outside to close the dialog'
This commit is contained in:
@@ -22,11 +22,40 @@ class Picker extends React.Component {
|
|||||||
super(props);
|
super(props);
|
||||||
this.defaultCalendarValue = null;
|
this.defaultCalendarValue = null;
|
||||||
this.calendarContainerRef = React.createRef();
|
this.calendarContainerRef = React.createRef();
|
||||||
|
this.inputRef = React.createRef();
|
||||||
|
this.state = {
|
||||||
|
isOpen: true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
closeDialog = () => {
|
||||||
|
this.setState({
|
||||||
|
isOpen: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
openDialog = () => {
|
||||||
|
this.setState({
|
||||||
|
isOpen: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
clickOutsideToClose = (e) => {
|
||||||
|
if (!this.inputRef.current.contains(e.target) &&
|
||||||
|
!this.calendarContainerRef.current.contains(e.target)) {
|
||||||
|
this.closeDialog();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
let lang = window.app.config.lang;
|
let lang = window.app.config.lang;
|
||||||
this.defaultCalendarValue = moment().locale(lang).clone();
|
this.defaultCalendarValue = moment().locale(lang).clone();
|
||||||
|
|
||||||
|
document.addEventListener('click', this.clickOutsideToClose);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
document.removeEventListener('click', this.clickOutsideToClose);
|
||||||
}
|
}
|
||||||
|
|
||||||
getCalendarContainer = () => {
|
getCalendarContainer = () => {
|
||||||
@@ -48,6 +77,7 @@ class Picker extends React.Component {
|
|||||||
getCalendarContainer={this.getCalendarContainer}
|
getCalendarContainer={this.getCalendarContainer}
|
||||||
calendar={calendar}
|
calendar={calendar}
|
||||||
value={props.value}
|
value={props.value}
|
||||||
|
open={this.state.isOpen}
|
||||||
onChange={props.onChange}
|
onChange={props.onChange}
|
||||||
>
|
>
|
||||||
{
|
{
|
||||||
@@ -59,9 +89,11 @@ class Picker extends React.Component {
|
|||||||
style={{ width: props.inputWidth || 250 }}
|
style={{ width: props.inputWidth || 250 }}
|
||||||
tabIndex="-1"
|
tabIndex="-1"
|
||||||
disabled={props.disabled}
|
disabled={props.disabled}
|
||||||
readOnly
|
readOnly={true}
|
||||||
value={value && value.format(FORMAT) || ''}
|
value={value && value.format(FORMAT) || ''}
|
||||||
className="form-control"
|
className="form-control"
|
||||||
|
onClick={this.openDialog}
|
||||||
|
ref={this.inputRef}
|
||||||
/>
|
/>
|
||||||
<div ref={this.calendarContainerRef} />
|
<div ref={this.calendarContainerRef} />
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user