Skip to content

Commit

Permalink
[nit] Misc code organization
Browse files Browse the repository at this point in the history
- Move classes/styling up to top of file
- add jsdoc block
- add clearer comments on why state is being used over refs for the input/panel refs
  • Loading branch information
cee-chen committed Oct 1, 2023
1 parent b9feb3d commit f1b2ae2
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/components/popover/input_popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,19 @@ export const EuiInputPopover: FunctionComponent<EuiInputPopoverProps> = ({
panelRef: _panelRef,
...props
}) => {
const euiThemeContext = useEuiTheme();
const classes = classnames('euiInputPopover', className);
const euiTheme = useEuiTheme();
const form = euiFormVariables(euiTheme);

/**
* Ref setup
*/

const popoverClassRef = useRef<EuiPopover>(null);
// The inputEl state ensures that width is correctly tracked on initial load
const [inputEl, setInputEl] = useState<HTMLElement | null>(null);
// The panelEl state ensures that width is correctly set every time the popover opens
const [panelEl, setPanelEl] = useState<HTMLElement | null>(null);
const popoverClassRef = useRef<EuiPopover | null>(null);

const inputRef = useCombinedRefs([setInputEl, _inputRef]);
const panelRef = useCombinedRefs([setPanelEl, _panelRef]);
Expand Down Expand Up @@ -131,9 +140,6 @@ export const EuiInputPopover: FunctionComponent<EuiInputPopoverProps> = ({
[disableFocusTrap, closePopover, panelPropsOnKeyDown]
);

const classes = classnames('euiInputPopover', className);
const form = euiFormVariables(euiThemeContext);

return (
<EuiPopover
css={css(fullWidth ? undefined : logicalCSS('max-width', form.maxWidth))}
Expand Down

0 comments on commit f1b2ae2

Please sign in to comment.