From 20a0213eccab01183a4e15642eb26ac644ba13d5 Mon Sep 17 00:00:00 2001 From: Cee Chen Date: Mon, 23 Oct 2023 12:18:50 -0700 Subject: [PATCH 1/6] [EuiInputPopover] Fix missing `onPanelResize` callback --- src/components/popover/input_popover.spec.tsx | 11 +++++++++++ src/components/popover/input_popover.tsx | 5 +++++ upcoming_changelogs/7305.md | 3 +++ 3 files changed, 19 insertions(+) create mode 100644 upcoming_changelogs/7305.md diff --git a/src/components/popover/input_popover.spec.tsx b/src/components/popover/input_popover.spec.tsx index 2e00958b3fa..e3ce9327c01 100644 --- a/src/components/popover/input_popover.spec.tsx +++ b/src/components/popover/input_popover.spec.tsx @@ -119,6 +119,17 @@ describe('EuiPopover', () => { .should('have.css', 'inline-size', '250px') .should('have.css', 'left', '50px'); }); + + it('calls `onPanelResize`', () => { + const onPanelResize = cy.stub().as('onPanelResize'); + cy.realMount( + + ); + cy.get('@onPanelResize').should('have.been.calledWith', 250); + + resizeInput(200); + cy.get('@onPanelResize').should('have.been.calledWith', 200); + }); }); describe('focus/tab management', () => { diff --git a/src/components/popover/input_popover.tsx b/src/components/popover/input_popover.tsx index 1089f289928..1fa0485a775 100644 --- a/src/components/popover/input_popover.tsx +++ b/src/components/popover/input_popover.tsx @@ -108,6 +108,11 @@ export const EuiInputPopover: FunctionComponent = ({ return inputWidth < panelMinWidth ? panelMinWidth : inputWidth; }, [panelMinWidth, inputWidth]); + // Resize callback + useEffect(() => { + onPanelResize?.(panelWidth); + }, [panelWidth, onPanelResize]); + useEffect(() => { if (panelEl) { // We have to modify the popover panel DOM node directly instead of using diff --git a/upcoming_changelogs/7305.md b/upcoming_changelogs/7305.md new file mode 100644 index 00000000000..c0124072fd1 --- /dev/null +++ b/upcoming_changelogs/7305.md @@ -0,0 +1,3 @@ +**Bug fixes** + +- Fixed `EuiInputPopover` not calling `onPanelResize` callback prop From 9c7411c8529a97db6169c496f0119fa3efd443fd Mon Sep 17 00:00:00 2001 From: Cee Chen Date: Mon, 23 Oct 2023 13:27:48 -0700 Subject: [PATCH 2/6] [misc] Type fixes/cleanup - optional / not related to main fix --- src/components/form/range/dual_range.tsx | 10 +++++----- src/components/form/range/utils.ts | 3 +-- src/components/popover/input_popover.tsx | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/components/form/range/dual_range.tsx b/src/components/form/range/dual_range.tsx index 07614a4c23e..90c2120dec2 100644 --- a/src/components/form/range/dual_range.tsx +++ b/src/components/form/range/dual_range.tsx @@ -280,7 +280,7 @@ export class EuiDualRangeClass extends Component< } lower = this._handleKeyDown(lower, event); } - if (lower >= this.upperValue || lower < this.props.min) return; + if (lower >= Number(this.upperValue) || lower < this.props.min) return; this._handleOnChange(lower, this.upperValue, event); }; @@ -298,7 +298,7 @@ export class EuiDualRangeClass extends Component< } upper = this._handleKeyDown(upper, event); } - if (upper <= this.lowerValue || upper > this.props.max) return; + if (upper <= Number(this.lowerValue) || upper > this.props.max) return; this._handleOnChange(this.lowerValue, upper, event); }; @@ -312,8 +312,8 @@ export class EuiDualRangeClass extends Component< lower = this._handleKeyDown(lower, event); upper = this._handleKeyDown(upper, event); } - if (lower >= this.upperValue || lower < this.props.min) return; - if (upper <= this.lowerValue || upper > this.props.max) return; + if (lower >= Number(this.upperValue) || lower < this.props.min) return; + if (upper <= Number(this.lowerValue) || upper > this.props.max) return; this._handleOnChange(lower, upper, event); }; @@ -377,7 +377,7 @@ export class EuiDualRangeClass extends Component< }); }; - onResize = (width?: number) => { + onResize = (width: number) => { this.setState({ rangeWidth: width, }); diff --git a/src/components/form/range/utils.ts b/src/components/form/range/utils.ts index 7c902151960..46bac7b63ed 100644 --- a/src/components/form/range/utils.ts +++ b/src/components/form/range/utils.ts @@ -12,7 +12,7 @@ export const calculateThumbPosition = ( value: number, min: number, max: number, - width: number, + trackWidth: number, thumbSize: number = EUI_THUMB_SIZE ) => { // Calculate the left position based on value @@ -21,7 +21,6 @@ export const calculateThumbPosition = ( let valuePosition = decimal <= 1 ? decimal : 1; valuePosition = valuePosition >= 0 ? valuePosition : 0; - const trackWidth = width ?? 0; const thumbToTrackRatio = thumbSize / trackWidth; const trackPositionScale = (1 - thumbToTrackRatio) * 100; diff --git a/src/components/popover/input_popover.tsx b/src/components/popover/input_popover.tsx index 1fa0485a775..efad183795b 100644 --- a/src/components/popover/input_popover.tsx +++ b/src/components/popover/input_popover.tsx @@ -44,7 +44,7 @@ export interface _EuiInputPopoverProps fullWidth?: boolean; input: EuiPopoverProps['button']; inputRef?: EuiPopoverProps['buttonRef']; - onPanelResize?: (width?: number) => void; + onPanelResize?: (width: number) => void; /** * By default, **EuiInputPopovers** inherit the same width as the passed input element. * However, if the input width is too small, you can pass a minimum panel width From 399a9a161f42d38e630c3c72f434e351ad28c761 Mon Sep 17 00:00:00 2001 From: Cee Chen Date: Mon, 23 Oct 2023 14:23:16 -0700 Subject: [PATCH 3/6] [EuiRangeTrack][setup] Remove `trackWidth` ref - in favor of tracking width state from parent component and passing it down as a prop - makes tests easier to mock as well --- .../__snapshots__/range_track.test.tsx.snap | 22 +++---- .../form/range/range_track.test.tsx | 62 ++++++++----------- src/components/form/range/range_track.tsx | 15 +---- 3 files changed, 41 insertions(+), 58 deletions(-) diff --git a/src/components/form/range/__snapshots__/range_track.test.tsx.snap b/src/components/form/range/__snapshots__/range_track.test.tsx.snap index 365d43e23fa..63d64482a0d 100644 --- a/src/components/form/range/__snapshots__/range_track.test.tsx.snap +++ b/src/components/form/range/__snapshots__/range_track.test.tsx.snap @@ -11,7 +11,7 @@ exports[`EuiRangeTrack is rendered 1`] = ` >