Datepicker: resize dropdown on tab switch
This commit is contained in:
parent
e766a37e58
commit
713dd242c7
|
@ -24,7 +24,7 @@ class DatePickerContent extends Component {
|
||||||
this.onTabSelect = this.onTabSelect.bind( this );
|
this.onTabSelect = this.onTabSelect.bind( this );
|
||||||
}
|
}
|
||||||
onTabSelect( tab ) {
|
onTabSelect( tab ) {
|
||||||
const { onUpdate, period } = this.props;
|
const { onUpdate, period, refreshDropdown } = this.props;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the period is `custom` and the user switches tabs to view the presets,
|
* If the period is `custom` and the user switches tabs to view the presets,
|
||||||
|
@ -34,6 +34,8 @@ class DatePickerContent extends Component {
|
||||||
if ( 'period' === tab && 'custom' === period ) {
|
if ( 'period' === tab && 'custom' === period ) {
|
||||||
onUpdate( { period: 'today' } );
|
onUpdate( { period: 'today' } );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refreshDropdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -78,11 +80,7 @@ class DatePickerContent extends Component {
|
||||||
] }
|
] }
|
||||||
className="woocommerce-filters-date__tabs"
|
className="woocommerce-filters-date__tabs"
|
||||||
activeClass="is-active"
|
activeClass="is-active"
|
||||||
initialTabName={
|
initialTabName={ 'custom' === period ? 'custom' : 'period' }
|
||||||
'custom' === period
|
|
||||||
? 'custom'
|
|
||||||
: 'period' /* Open to current tab https://github.com/WordPress/gutenberg/pull/6885 */
|
|
||||||
}
|
|
||||||
onSelect={ this.onTabSelect }
|
onSelect={ this.onTabSelect }
|
||||||
>
|
>
|
||||||
{ selectedTab => (
|
{ selectedTab => (
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
/**
|
/**
|
||||||
* External dependencies
|
* External dependencies
|
||||||
*/
|
*/
|
||||||
|
import { Component, createRef } from '@wordpress/element';
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { Component } from '@wordpress/element';
|
|
||||||
import { Dropdown } from '@wordpress/components';
|
import { Dropdown } from '@wordpress/components';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
|
@ -26,10 +26,19 @@ class DatePicker extends Component {
|
||||||
super( props );
|
super( props );
|
||||||
this.state = this.getResetState();
|
this.state = this.getResetState();
|
||||||
|
|
||||||
|
this.dropdownRef = createRef();
|
||||||
|
|
||||||
this.update = this.update.bind( this );
|
this.update = this.update.bind( this );
|
||||||
this.onSelect = this.onSelect.bind( this );
|
this.onSelect = this.onSelect.bind( this );
|
||||||
this.isValidSelection = this.isValidSelection.bind( this );
|
this.isValidSelection = this.isValidSelection.bind( this );
|
||||||
this.resetCustomValues = this.resetCustomValues.bind( this );
|
this.resetCustomValues = this.resetCustomValues.bind( this );
|
||||||
|
this.refreshDropdown = this.refreshDropdown.bind( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshDropdown() {
|
||||||
|
setTimeout( () => {
|
||||||
|
this.dropdownRef.current.popoverRef && this.dropdownRef.current.popoverRef.current.refresh();
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
getResetState() {
|
getResetState() {
|
||||||
|
@ -115,6 +124,7 @@ class DatePicker extends Component {
|
||||||
<div className="woocommerce-filters-date">
|
<div className="woocommerce-filters-date">
|
||||||
<p>{ __( 'Date Range', 'wc-admin' ) }:</p>
|
<p>{ __( 'Date Range', 'wc-admin' ) }:</p>
|
||||||
<Dropdown
|
<Dropdown
|
||||||
|
ref={ this.dropdownRef }
|
||||||
contentClassName="woocommerce-filters-date__content"
|
contentClassName="woocommerce-filters-date__content"
|
||||||
position="bottom"
|
position="bottom"
|
||||||
expandOnMobile
|
expandOnMobile
|
||||||
|
@ -142,6 +152,7 @@ class DatePicker extends Component {
|
||||||
afterError={ afterError }
|
afterError={ afterError }
|
||||||
beforeError={ beforeError }
|
beforeError={ beforeError }
|
||||||
shortDateFormat={ shortDateFormat }
|
shortDateFormat={ shortDateFormat }
|
||||||
|
refreshDropdown={ this.refreshDropdown }
|
||||||
/>
|
/>
|
||||||
) }
|
) }
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in New Issue