Skip to content

fix(Search Input): use popper to control the popup in advanced search#7621

Merged
nicolethoen merged 3 commits intopatternfly:mainfrom
bartoval:advanced_filter_search_position_no_longer_absolute
Jul 8, 2022
Merged

fix(Search Input): use popper to control the popup in advanced search#7621
nicolethoen merged 3 commits intopatternfly:mainfrom
bartoval:advanced_filter_search_position_no_longer_absolute

Conversation

@bartoval
Copy link
Copy Markdown
Member

What: Closes #7592

@patternfly-build
Copy link
Copy Markdown
Collaborator

patternfly-build commented Jun 28, 2022

@bartoval bartoval force-pushed the advanced_filter_search_position_no_longer_absolute branch from 783c3c8 to 346efb7 Compare June 28, 2022 14:04
@bartoval bartoval self-assigned this Jun 28, 2022
@bartoval bartoval force-pushed the advanced_filter_search_position_no_longer_absolute branch 2 times, most recently from 3cfdc2e to 4fd7d62 Compare June 29, 2022 19:49
@bartoval bartoval force-pushed the advanced_filter_search_position_no_longer_absolute branch from 4fd7d62 to cb46af6 Compare June 29, 2022 20:02
<div className={css(className, styles.searchInput)} ref={searchInputRef} {...props}>
{buildSearchTextInputGroupWithExtraButtons()}
const advancedSearch = (
<span>
Copy link
Copy Markdown
Member Author

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

@bartoval bartoval requested review from nicolethoen and tlabaj June 29, 2022 20:33
trigger={buildSearchTextInputGroupWithExtraButtons({ id: 'custom-advanced-search' })}
popper={advancedSearch}
isVisible={isSearchMenuOpen}
enableFlip={false}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should enableFlip=true by default

popper={advancedSearch}
isVisible={isSearchMenuOpen}
enableFlip={false}
appendTo={() => document.querySelector('#custom-advanced-search')}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot hardcode this value. It should be something that is configurable the prop could be the same or inspired by the appendTo prop from TimePicker.tsx

/** The container to append the advanced search form to. Defaults to 'parent'.
   * If your form is being cut off you can append it to an element higher up the DOM tree.
   * Some examples:
   * appendTo="parent"
   * appendTo={() => document.body}
   * appendTo={document.getElementById('target')}
   */
  appendTo?: HTMLElement | (() => HTMLElement) | 'inline' | 'parent';

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about that.
We want to append this menu to 'SearchTextInputGroup' (we set the value 'custom-advanced-search' as id) every time and not to an external DOM element.

Maybe I am missing something.
Could you please provide an example of where we need to configure this element outside the component?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible that someone will put an advanced search into a Wizard modal for example and that would get clipped or formatted incorrectly relative to the wizard or modal. Those tend to be some the edge cases we are allowing for.

Additionally, if someone wants an inline advanced search, where opening the modal does (for whatever reason) push down the contents of the page so the advanced search is not overlaying the results, that should be possible using the 'inline' value of 'appendTo'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks! 👍🏼
So I think we can:

  • keep the current behavior as default (without passing the prop appendTo). (popper)
  • provide the inline option to push down the content ( no popper)
  • add the possibility to pass an external DOM element (popper)

@bartoval bartoval force-pushed the advanced_filter_search_position_no_longer_absolute branch 3 times, most recently from 64be51d to 83c784e Compare July 6, 2022 08:15
* menuAppendTo={() => document.body}
* menuAppendTo={document.getElementById('target')}
*/
menuAppendTo?: HTMLElement | (() => HTMLElement) | 'inline';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the prop name menuAppendTo is a little misleading since the Menu is a component we have and we are not using a Menu in this case, but a panel. So I think it could be panelAppendTo or appendTo or maybe something else.

Copy link
Copy Markdown
Contributor

@nicolethoen nicolethoen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I have one request to update the prop name

@bartoval bartoval force-pushed the advanced_filter_search_position_no_longer_absolute branch from 83c784e to da06c6a Compare July 6, 2022 14:00
@bartoval bartoval requested a review from nicolethoen July 6, 2022 14:01
Comment thread packages/react-core/src/components/SearchInput/SearchInput.tsx
Copy link
Copy Markdown
Collaborator

@wise-king-sullyman wise-king-sullyman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! One request: can you add a couple of tests to verify the behavior of appendTo? After that I'll be ready to approve 🙂

Copy link
Copy Markdown
Collaborator

@wise-king-sullyman wise-king-sullyman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple nits!

userEvent.click(screen.getByRole('button', { name: 'Search' }));

userEvent.click(screen.getByRole('button', { name: 'Open advanced search' }));
expect(screen.getByTestId('test-id').querySelector('.pf-c-panel')).toBeInTheDocument()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: rather than using querySelector + toBeInTheDocument to determine where the search menu is being placed in the DOM can you use an RTL query to select the form (or something in it) and maybe the toContainElement matcher?

Reason being that I believe this would better replicate the actual user experience with the component.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Thanks 👍🏼

@bartoval bartoval force-pushed the advanced_filter_search_position_no_longer_absolute branch 2 times, most recently from eafa708 to 9cd5fb7 Compare July 8, 2022 15:19
@bartoval bartoval force-pushed the advanced_filter_search_position_no_longer_absolute branch from 9cd5fb7 to f726d50 Compare July 8, 2022 15:40
Copy link
Copy Markdown
Collaborator

@wise-king-sullyman wise-king-sullyman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! 🚀

@nicolethoen nicolethoen merged commit 13a8d5f into patternfly:main Jul 8, 2022
jenny-s51 pushed a commit to jenny-s51/patternfly-react that referenced this pull request Jul 26, 2022
…patternfly#7621)

* fix(SearchInput): use popper to control the popup in advanced search

* refactor(Search input): update PR comments

* refactor(SearchInput): add unit tets
<div className={css(className, styles.searchInput)} ref={searchInputRef} {...props}>
{buildSearchTextInputGroupWithExtraButtons()}
const AdvancedSearch = (
<span>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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, .pf-c-panel.pf-c-search-intput__menu).

This element should be a <div> though, a <span> is an inline element and its permitted content is phrasing content. So technically it's invalid HTML to put non-phrasing content in a <span>, though it works just fine. Created an issue for that here - #7796

Also it's worth noting that appendTo="inline" just drops the panel in the layout and pushes everything below it down (it doesn't display on top of the stuff below it). A few questions around that:

  • Should appendTo be menuAppendTo like the other components that have a menu in them that popper can position?
  • Is that the intended behavior of appendTo="inline" or should that display on top of the stuff below it like it used to - it just won't use popper. Not sure how we'd do that if we want to continue to use the panel component there, but that would be inline with the other menus that support menuAppendTo.
  • If we are going to leave it so that it pushes the stuff below the panel down, should we remove the "raised" modifier from the panel since the shadow implies depth/overlay?

Copy link
Copy Markdown
Member Author

@bartoval bartoval Aug 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mcoker thanks for your comments! They are very interesting.

  • I will pick up the issue

Regarding your questions:

  • there is comment above about that and using menuAppendTo is a little misleading since the Menu is a component we have and we are not using a Menu in this case.

  • Yes this behaviour is predicted like the TimePicker (@nicolethoen )

  • Not sure about it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bartoval thanks!!

there is comment above about that and using menuAppendTo is a little misleading since the Menu is a component we have and we are not using a Menu in this case.

👍 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, menuAppendTo would still be fine and wouldn't necessarily need to change IMO since we shouldn't be tying the prop name to the component used in the first place and we're using menu as a concept. Also I'd probably say that [menu/thing]AppendTo would be used on the component that has a thing that pops up, and appendTo would be more appropriate on the thing that pops up itself. Just my $0.02 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug - SearchInput - breaking change in advanced filter's panel-based popover; positioning is no longer absolute

6 participants