Skip to content

Commit

Permalink
🎺 Add inputPopoverProps support 🎺
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen committed Oct 2, 2023
1 parent 2e36462 commit d50c5f8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
34 changes: 32 additions & 2 deletions src/components/combo_box/combo_box.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ before(() => {
});

describe('EuiComboBox', () => {
describe('Focus management', () => {
describe('focus management', () => {
it('keeps focus on the input box when clicking a disabled item', () => {
cy.realMount(
<EuiComboBox
Expand Down Expand Up @@ -113,6 +113,37 @@ describe('EuiComboBox', () => {
});
});

describe('inputPopoverProps', () => {
it('allows setting a minimum popover width', () => {
cy.mount(
<EuiComboBox
options={[{ label: 'Test' }]}
selectedOptions={[]}
onChange={() => {}}
data-test-subj="combobox"
inputPopoverProps={{
panelMinWidth: 300,
anchorPosition: 'downCenter',
}}
style={{ margin: '0 auto' }}
/>
);
cy.get('[data-test-subj="comboBoxInput"]').click();

cy.get('[data-popover-panel]')
.should('have.css', 'inline-size', '400px')
.should('have.css', 'left', '50px');

cy.get('[data-test-subj="combobox"]').then(
($el) => ($el[0].style.width = '200px')
);

cy.get('[data-popover-panel]')
.should('have.css', 'inline-size', '300px')
.should('have.css', 'left', '100px');
});
});

describe('truncation', () => {
const sharedProps = {
style: { width: 200 },
Expand Down Expand Up @@ -201,7 +232,6 @@ describe('EuiComboBox', () => {
});
});
});

describe('selection', () => {
const defaultOptions: Array<EuiComboBoxOptionOption<{}>> = [
{ label: 'Item 1' },
Expand Down
15 changes: 12 additions & 3 deletions src/components/combo_box/combo_box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import classNames from 'classnames';

import { htmlIdGenerator, keys } from '../../services';
import { CommonProps } from '../common';
import { EuiInputPopover } from '../popover';
import { EuiInputPopover, EuiInputPopoverProps } from '../popover';
import { EuiI18n } from '../i18n';
import { EuiFormControlLayoutProps } from '../form';
import type { EuiTextTruncateProps } from '../text_truncate';
Expand Down Expand Up @@ -162,6 +162,13 @@ export interface _EuiComboBoxProps<T>
* text will always take precedence.
*/
truncationProps?: Partial<Omit<EuiTextTruncateProps, 'text' | 'children'>>;
/**
* Allows customizing the underlying EuiInputPopover component
* (except for props that control state).
*/
inputPopoverProps?: Partial<
Omit<EuiInputPopoverProps, 'input' | 'isOpen' | 'closePopover'>
>;
}

/**
Expand Down Expand Up @@ -710,6 +717,7 @@ export class EuiComboBox<T> extends Component<
append,
autoFocus,
truncationProps,
inputPopoverProps,
'aria-label': ariaLabel,
'aria-labelledby': ariaLabelledby,
...rest
Expand Down Expand Up @@ -810,12 +818,13 @@ export class EuiComboBox<T> extends Component<
ref={this.comboBoxRefCallback}
>
<EuiInputPopover
isOpen={isListOpen}
closePopover={this.closeList}
fullWidth={fullWidth}
panelPaddingSize="none"
disableFocusTrap={true}
closeOnScroll={true}
{...inputPopoverProps}
isOpen={isListOpen}
closePopover={this.closeList}
input={
<EuiComboBoxInput
compressed={compressed}
Expand Down

0 comments on commit d50c5f8

Please sign in to comment.