-
Notifications
You must be signed in to change notification settings - Fork 384
fix(Search Input): use popper to control the popup in advanced search #7621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| import * as React from 'react'; | ||
| import { css } from '@patternfly/react-styles'; | ||
| import styles from '@patternfly/react-styles/css/components/SearchInput/search-input'; | ||
| import { Button, ButtonVariant } from '../Button'; | ||
| import { Badge } from '../Badge'; | ||
| import AngleDownIcon from '@patternfly/react-icons/dist/esm/icons/angle-down-icon'; | ||
|
|
@@ -12,6 +11,7 @@ import ArrowRightIcon from '@patternfly/react-icons/dist/esm/icons/arrow-right-i | |
| import { AdvancedSearchMenu } from './AdvancedSearchMenu'; | ||
| import { TextInputGroup, TextInputGroupMain, TextInputGroupUtilities } from '../TextInputGroup'; | ||
| import { InputGroup } from '../InputGroup'; | ||
| import { Popper } from '../../helpers'; | ||
|
|
||
| export interface SearchAttribute { | ||
| /** The search attribute's value to be provided in the search input's query string. | ||
|
|
@@ -83,6 +83,13 @@ export interface SearchInputProps extends Omit<React.HTMLProps<HTMLDivElement>, | |
| /** Delimiter in the query string for pairing attributes with search values. | ||
| * Required whenever attributes are passed as props */ | ||
| advancedSearchDelimiter?: string; | ||
| /** The container to append the menu to. | ||
| * If your menu is being cut off you can append it to an element higher up the DOM tree. | ||
| * Some examples: | ||
| * appendTo={() => document.body} | ||
| * appendTo={document.getElementById('target')} | ||
| */ | ||
| appendTo?: HTMLElement | (() => HTMLElement) | 'inline'; | ||
| } | ||
|
|
||
| const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({ | ||
|
|
@@ -112,6 +119,7 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({ | |
| nextNavigationButtonAriaLabel = 'Next', | ||
| submitSearchButtonLabel = 'Search', | ||
| isDisabled = false, | ||
| appendTo, | ||
| ...props | ||
| }: SearchInputProps) => { | ||
| const [isSearchMenuOpen, setIsSearchMenuOpen] = React.useState(false); | ||
|
|
@@ -277,11 +285,9 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({ | |
|
|
||
| if (!!onSearch || attributes.length > 0 || !!onToggleAdvancedSearch) { | ||
| if (attributes.length > 0) { | ||
| return ( | ||
| <div className={css(className, styles.searchInput)} ref={searchInputRef} {...props}> | ||
| {buildSearchTextInputGroupWithExtraButtons()} | ||
| const AdvancedSearch = ( | ||
| <span> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bartoval Apologies for the super late comment, I was following up on something I made a note about a while ago. FWIW with the original issue, we should always try and avoid applying multiple component styles to an element (ie, This element should be a Also it's worth noting that
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mcoker thanks for your comments! They are very interesting.
Regarding your questions:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bartoval thanks!!
👍 got it. I agree, that could be confusing. I would probably argue that menu is more of a concept there to refer to the thing that pops open in the component, and that could be used with whatever component pops up. It seems like it might be more predictable/consistent that way. As in if we stopped using the "menu" component and used some other component for the thing that pops up, |
||
| <AdvancedSearchMenu | ||
| className={styles.searchInputMenu} | ||
|
wise-king-sullyman marked this conversation as resolved.
|
||
| value={value} | ||
| parentRef={searchInputRef} | ||
| parentInputRef={searchInputInputRef} | ||
|
|
@@ -298,8 +304,29 @@ const SearchInputBase: React.FunctionComponent<SearchInputProps> = ({ | |
| getAttrValueMap={getAttrValueMap} | ||
| isSearchMenuOpen={isSearchMenuOpen} | ||
| /> | ||
| </span> | ||
| ); | ||
|
|
||
| const AdvancedSearchWithPopper = ( | ||
| <div className={css(className)} ref={searchInputRef} {...props}> | ||
| <Popper | ||
| trigger={buildSearchTextInputGroupWithExtraButtons()} | ||
| popper={AdvancedSearch} | ||
| isVisible={isSearchMenuOpen} | ||
| enableFlip={true} | ||
| appendTo={() => appendTo || searchInputRef.current} | ||
| /> | ||
| </div> | ||
| ); | ||
|
|
||
| const AdvancedSearchInline = ( | ||
| <div className={css(className)} ref={searchInputRef} {...props}> | ||
| {buildSearchTextInputGroupWithExtraButtons()} | ||
| {AdvancedSearch} | ||
| </div> | ||
| ); | ||
|
|
||
| return appendTo !== 'inline' ? AdvancedSearchWithPopper : AdvancedSearchInline; | ||
| } | ||
|
|
||
| return buildSearchTextInputGroupWithExtraButtons({ ...searchInputProps }); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need a native HTML markup here, otherwise, the popper is not going to calculate the position and set the item absolute