Skip to content

Commit

Permalink
[EuiSuperDatePicker] Updated the onFocus call on buttonProps and pret…
Browse files Browse the repository at this point in the history
…tyDuration (elastic#4924)
  • Loading branch information
UzairNoman committed Nov 2, 2022
1 parent b3aad72 commit 0fec4de
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ exports[`EuiSuperDatePicker is rendered 1`] = `
className="euiSuperDatePicker testClass1 testClass2"
data-test-subj="test subject string"
isDisabled={false}
onClick={[Function]}
onKeyUp={[Function]}
prepend={
<EuiQuickSelectPopover
applyTime={[Function]}
Expand Down Expand Up @@ -239,10 +237,18 @@ exports[`EuiSuperDatePicker is rendered 1`] = `
>
<EuiDatePickerRange
className="euiDatePickerRange--inGroup"
endDateControl={<div />}
endDateControl={
<div
onFocus={[Function]}
/>
}
iconType={false}
isCustom={true}
startDateControl={<div />}
startDateControl={
<div
onFocus={[Function]}
/>
}
>
<button
className="euiSuperDatePicker__prettyFormat"
Expand Down Expand Up @@ -338,8 +344,6 @@ exports[`EuiSuperDatePicker props accepts data-test-subj and passes to EuiFormCo
className="euiSuperDatePicker"
data-test-subj="mySuperDatePicker"
isDisabled={false}
onClick={[Function]}
onKeyUp={[Function]}
prepend={
<EuiQuickSelectPopover
applyTime={[Function]}
Expand Down Expand Up @@ -566,10 +570,18 @@ exports[`EuiSuperDatePicker props accepts data-test-subj and passes to EuiFormCo
>
<EuiDatePickerRange
className="euiDatePickerRange--inGroup"
endDateControl={<div />}
endDateControl={
<div
onFocus={[Function]}
/>
}
iconType={false}
isCustom={true}
startDateControl={<div />}
startDateControl={
<div
onFocus={[Function]}
/>
}
>
<button
className="euiSuperDatePicker__prettyFormat"
Expand Down Expand Up @@ -665,8 +677,6 @@ exports[`EuiSuperDatePicker props compressed is rendered 1`] = `
className="euiSuperDatePicker"
compressed={true}
isDisabled={false}
onClick={[Function]}
onKeyUp={[Function]}
prepend={
<EuiQuickSelectPopover
applyTime={[Function]}
Expand Down Expand Up @@ -893,10 +903,18 @@ exports[`EuiSuperDatePicker props compressed is rendered 1`] = `
>
<EuiDatePickerRange
className="euiDatePickerRange--inGroup"
endDateControl={<div />}
endDateControl={
<div
onFocus={[Function]}
/>
}
iconType={false}
isCustom={true}
startDateControl={<div />}
startDateControl={
<div
onFocus={[Function]}
/>
}
>
<button
className="euiSuperDatePicker__prettyFormat"
Expand Down Expand Up @@ -1028,8 +1046,6 @@ exports[`EuiSuperDatePicker props isQuickSelectOnly is rendered 1`] = `
<EuiFormControlLayout
className="euiSuperDatePicker"
isDisabled={false}
onClick={[Function]}
onKeyUp={[Function]}
prepend={
<EuiQuickSelectPopover
applyTime={[Function]}
Expand Down Expand Up @@ -1289,8 +1305,6 @@ exports[`EuiSuperDatePicker props showUpdateButton can be false 1`] = `
<EuiFormControlLayout
className="euiSuperDatePicker"
isDisabled={false}
onClick={[Function]}
onKeyUp={[Function]}
prepend={
<EuiQuickSelectPopover
applyTime={[Function]}
Expand Down Expand Up @@ -1517,10 +1531,18 @@ exports[`EuiSuperDatePicker props showUpdateButton can be false 1`] = `
>
<EuiDatePickerRange
className="euiDatePickerRange--inGroup"
endDateControl={<div />}
endDateControl={
<div
onFocus={[Function]}
/>
}
iconType={false}
isCustom={true}
startDateControl={<div />}
startDateControl={
<div
onFocus={[Function]}
/>
}
>
<button
className="euiSuperDatePicker__prettyFormat"
Expand Down Expand Up @@ -1594,8 +1616,6 @@ exports[`EuiSuperDatePicker props showUpdateButton can be iconOnly 1`] = `
<EuiFormControlLayout
className="euiSuperDatePicker"
isDisabled={false}
onClick={[Function]}
onKeyUp={[Function]}
prepend={
<EuiQuickSelectPopover
applyTime={[Function]}
Expand Down Expand Up @@ -1822,10 +1842,18 @@ exports[`EuiSuperDatePicker props showUpdateButton can be iconOnly 1`] = `
>
<EuiDatePickerRange
className="euiDatePickerRange--inGroup"
endDateControl={<div />}
endDateControl={
<div
onFocus={[Function]}
/>
}
iconType={false}
isCustom={true}
startDateControl={<div />}
startDateControl={
<div
onFocus={[Function]}
/>
}
>
<button
className="euiSuperDatePicker__prettyFormat"
Expand Down Expand Up @@ -1920,8 +1948,6 @@ exports[`EuiSuperDatePicker props width can be auto 1`] = `
<EuiFormControlLayout
className="euiSuperDatePicker"
isDisabled={false}
onClick={[Function]}
onKeyUp={[Function]}
prepend={
<EuiQuickSelectPopover
applyTime={[Function]}
Expand Down Expand Up @@ -2148,10 +2174,18 @@ exports[`EuiSuperDatePicker props width can be auto 1`] = `
>
<EuiDatePickerRange
className="euiDatePickerRange--inGroup"
endDateControl={<div />}
endDateControl={
<div
onFocus={[Function]}
/>
}
iconType={false}
isCustom={true}
startDateControl={<div />}
startDateControl={
<div
onFocus={[Function]}
/>
}
>
<button
className="euiSuperDatePicker__prettyFormat"
Expand Down Expand Up @@ -2246,8 +2280,6 @@ exports[`EuiSuperDatePicker props width can be full 1`] = `
<EuiFormControlLayout
className="euiSuperDatePicker"
isDisabled={false}
onClick={[Function]}
onKeyUp={[Function]}
prepend={
<EuiQuickSelectPopover
applyTime={[Function]}
Expand Down Expand Up @@ -2474,10 +2506,18 @@ exports[`EuiSuperDatePicker props width can be full 1`] = `
>
<EuiDatePickerRange
className="euiDatePickerRange--inGroup"
endDateControl={<div />}
endDateControl={
<div
onFocus={[Function]}
/>
}
iconType={false}
isCustom={true}
startDateControl={<div />}
startDateControl={
<div
onFocus={[Function]}
/>
}
>
<button
className="euiSuperDatePicker__prettyFormat"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ export const EuiDatePopoverButton: FunctionComponent<EuiDatePopoverButtonProps>
const button = (
<button
onClick={onPopoverToggle}
onFocus={() => console.log('This is invoking twice')}
className={classes}
title={title}
disabled={isDisabled}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,19 +167,13 @@ describe('EuiSuperDatePicker', () => {
);
});

test('keyup or click on FCLayout or DatePickerRange should invoke onFocus on SuperDatePicker', () => {
test('should invoke onFocus on SuperDatePicker', () => {
const focusMock = jest.fn();

const componentFocus = mount<EuiSuperDatePickerInternal>(
const componentFocus = shallow<EuiSuperDatePickerInternal>(
<EuiSuperDatePicker onTimeChange={noop} onFocus={focusMock} />
);

componentFocus.find('EuiFormControlLayout').simulate('keyUp');
componentFocus.find('EuiDatePickerRange').simulate('keyUp');
componentFocus.find('EuiFormControlLayout').simulate('click');
componentFocus.find('EuiDatePickerRange').simulate('click');

expect(focusMock).toBeCalledTimes(4);
componentFocus.dive().simulate('focus');
expect(focusMock).toBeCalledTimes(1);
});

describe('showUpdateButton', () => {
Expand Down
24 changes: 9 additions & 15 deletions src/components/date_picker/super_date_picker/super_date_picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export type EuiSuperDatePickerProps = CommonProps & {
/**
* Triggered whenever the EuiSuperDatePicker is focused
*/
onFocus?: FocusEventHandler<HTMLDivElement>;
onFocus?: FocusEventHandler;

/**
* Callback for when the refresh interval is fired.
Expand Down Expand Up @@ -398,8 +398,12 @@ export class EuiSuperDatePickerInternal extends Component<
timeFormat,
utcOffset,
compressed,
onFocus,
} = this.props;

const handleFocusActivity = (e: React.FocusEvent) => {
onFocus?.(e);
};
if (
showPrettyDuration &&
!isStartDatePopoverOpen &&
Expand All @@ -410,8 +414,8 @@ export class EuiSuperDatePickerInternal extends Component<
className="euiDatePickerRange--inGroup"
iconType={false}
isCustom
startDateControl={<div />}
endDateControl={<div />}
startDateControl={<div onFocus={(e) => handleFocusActivity(e)} />}
endDateControl={<div onFocus={(e) => handleFocusActivity(e)} />}
>
<button
className={classNames('euiSuperDatePicker__prettyFormat', {
Expand Down Expand Up @@ -459,6 +463,7 @@ export class EuiSuperDatePickerInternal extends Component<
onPopoverToggle={this.onStartDatePopoverToggle}
onPopoverClose={this.onStartDatePopoverClose}
timeOptions={timeOptions}
buttonProps={{ onFocus: (e) => handleFocusActivity(e) }}
/>
}
endDateControl={
Expand All @@ -479,6 +484,7 @@ export class EuiSuperDatePickerInternal extends Component<
onPopoverToggle={this.onEndDatePopoverToggle}
onPopoverClose={this.onEndDatePopoverClose}
timeOptions={timeOptions}
buttonProps={{ onFocus: (e) => handleFocusActivity(e) }}
/>
}
/>
Expand Down Expand Up @@ -538,7 +544,6 @@ export class EuiSuperDatePickerInternal extends Component<
isDisabled,
isPaused,
onRefreshChange,
onFocus,
recentlyUsedRanges,
refreshInterval,
showUpdateButton,
Expand All @@ -553,15 +558,6 @@ export class EuiSuperDatePickerInternal extends Component<
// Force reduction in width if showing quick select only
const width = isQuickSelectOnly ? 'auto' : _width;

const handleInputActivity = (
event:
| React.KeyboardEvent<HTMLInputElement>
| React.MouseEvent<HTMLInputElement>
| any
) => {
if (onFocus) onFocus(event);
};

const autoRefreshAppend: EuiFormControlLayoutProps['append'] = !isPaused ? (
<EuiAutoRefreshButton
className="euiFormControlLayout__append"
Expand Down Expand Up @@ -627,8 +623,6 @@ export class EuiSuperDatePickerInternal extends Component<
compressed={compressed}
isDisabled={isDisabled}
prepend={quickSelect}
onClick={handleInputActivity}
onKeyUp={handleInputActivity}
append={autoRefreshAppend}
data-test-subj={dataTestSubj}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ export type EuiFormControlLayoutProps = CommonProps &
* Creates an input group with element(s) coming after children.
* `string` | `ReactElement` or an array of these
*/

onClick?: (e: React.MouseEvent<HTMLInputElement>) => void;
append?: PrependAppendType;
children?: ReactNode;
icon?: EuiFormControlLayoutIconsProps['icon'];
Expand Down

0 comments on commit 0fec4de

Please sign in to comment.