Skip to content
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

AutocompleteInput suggestions list location in filters #2259

Closed
despatates opened this issue Aug 31, 2018 · 9 comments
Closed

AutocompleteInput suggestions list location in filters #2259

despatates opened this issue Aug 31, 2018 · 9 comments
Labels

Comments

@despatates
Copy link
Contributor

General description
In filters of a List module, if a ReferenceInput with AutocompleteInput is moved after adding/removing another filter, the suggestions list stays at the old location.

What you were expecting:

When I add a new filter, I want the suggestions list of the previous AutocompleteInput to be moved to the right place.

What happened instead:

When a new filter is added/removed to a List, the AutocompleteInput is moved to the right place, but the suggestions list opens at the old location of the filter.

Steps to reproduce:

When adding a filter:
ezgif-3-e5904e8e53

When removing a filter:
ezgif-3-933ddc5008

Related code:

const OrderFilters = props => (
  <Filter {...props}>
    <TextInput source="company" />
    <ReferenceInput
      source="customer_id"
      reference="customer"
      allowEmpty
    >
      <AutocompleteInput optionText="name" />
    </ReferenceInput>
    <ReferenceInput
      source="carrier_id"
      reference="carrier"
      allowEmpty
    >
      <AutocompleteInput optionText="name" />
    </ReferenceInput>
  </Filter>
);

const OrderList = props => (
<List {...props} filters={<OrderFilters />}>
 [...]
</List>

Other information:

No error stacktrace.

Environment

  • React-admin version: 2.2.3
  • Last version that did not exhibit the issue (if applicable): unknown
  • React version: 16.4.13
  • Browser: Chrome 68.0.3440.106
@fzaninotto
Copy link
Member

wow, such a weird bug! Thanks for reporting it.

@fzaninotto fzaninotto added the bug label Aug 31, 2018
@vascofg
Copy link
Contributor

vascofg commented Sep 3, 2018

Could this be related to #2256?

@fzaninotto
Copy link
Member

possibly

@despatates
Copy link
Contributor Author

I just saw the new component AutocompleteArrayInput introduced with v2.3.0 suffers the same effect.

(See when adding tags Rock and Crossfit)

AutocompleteArrayInput

@selenyillar
Copy link

Not only in filters; if the suggestion list opens upward, when you search something, the list sticks to the top as it narrows.

screen shot 2019-02-06 at 10 37 58

tiagoschenkel added a commit to tiagoschenkel/react-admin that referenced this issue Feb 7, 2019
@tiagoschenkel
Copy link
Contributor

I had the same error here and found a possible solution.

The problem happens because the Popper component used to render the choices is a stateless component.

I noticed that when the original input element moves, React is keeping the old Popper without forcing it to redraw.

My solution is to create a new object that mimics the original input element. Doing this, we force the component to be redrawn, since the anchor element will always be new.

const anchorEl = !this.inputEl
            ? null
            : {
                  getBoundingClientRect: () =>
                      this.inputEl.getBoundingClientRect(),
              };

Then I'm using this anchorEl in the Popper component.

Here is my implementation, let me know if is fine for a merge request:
tiagoschenkel@3e58c94

@tiagoschenkel
Copy link
Contributor

I noticed that I was forcing the Popper element to redraw on every call to the renderSuggestionsContainer.

So now I'm keeping a reference to the old position and only forcing the redraw when the inputEl moves to a new location:
tiagoschenkel@33fafcf

I still don't know if this is the proper way to solve this issue, maybe we can store the inputEl and anchorEl elements in the state of the component.

My solution is based on this example from Material-UI docs:
https://v1-5-0.material-ui.com/utils/popper/#faked-reference-object

@selenyillar
Copy link

Can you please also add this solution on AutocompleteInput?
With this commit, now it seems only the AutocompleteArrayInput has fixed.

@tiagoschenkel
Copy link
Contributor

@selenyillar, #2928 solves the problem also for AutocompleteInput.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants