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

[Autocomplete] Add anchor to the textfield, not the Window position #6162

Closed
haydencrain opened this issue Feb 16, 2017 · 11 comments
Closed
Labels
component: autocomplete This is the name of the generic UI component, not the React module!

Comments

@haydencrain
Copy link

haydencrain commented Feb 16, 2017

Description

Currently the Autocomplete popover responds when the entire window is scrolled. Is it possible to set it so that it anchors to a particular container scroll?

Images & references

ezgif com-optimize
In the example, the window was set to a height of 140% for the purpose of showing that the popover responds to the window, but not the container.

@Sharlaan
Copy link

How did you define your AutoComplete's prop anchorOrigin ?

If the menu is anchored to the window, it may sound like a missing .bind(this) defaulting this to window ...

@jadus
Copy link

jadus commented Feb 16, 2017

Same problem here.
My autocomplete is in a scrollable dialog and the menu doesn't move when the dialog is crolled
Does anyone has a workaround ?
@Sharlaan What do you mean exactly ?
here is my component :

<AutoComplete
    name="routeSetter"
    anchorOrigin={{vertical: 'bottom', horizontal: 'left'}}
    value={this.state.routeSetter}
    searchText={this.state.routeSetter}
    filter={AutoComplete.noFilter}
    dataSource={routeSetters[gym]}
    onNewRequest={this.routeSetterChange}
    openOnFocus={true}
/>

where would you put a .bind(this ?

@Sharlaan
Copy link

Nevermind, without any code to review, i was assuming some dynamic function assigned to anchorOrigin. Such function must have this correctly bound, but it's not your case.

@haydencrain
Copy link
Author

My apologies for not supplying code. My component is set out the same as @jadus.

I am also able to recreate this is in the material-ui docs:
In Popover, I can apply a max-height: 200px and overflow: scroll to one of the containers. When scrolling with the popover open, the container scroll seems to lock.
popover

However, In Autocomplete, if I apply max-height: 200px and overflow: scroll like I did in the Popover docs, the container scroll does not lock, and so the menu does not move in line with the text field.
autocomplete

Looking at the Popover source I've noticed the reference is pointing to window. Is there any way I can map the reference to the div?

@Sharlaan
Copy link

Looking at the Popover source I've noticed the reference is pointing to window

which line ?

@haydencrain
Copy link
Author

From material-ui/src/Popover/Popover.js, Line 406:

<EventListener
     target="window"
     onScroll={this.handleScroll}
     onResize={this.handleResize}
/>

Looks like the target points to window and scroll position is handled here.

@haydencrain haydencrain changed the title Autocomplete: Add anchor to the textfield, not the Window position [Autocomplete] Add anchor to the textfield, not the Window position Feb 17, 2017
@Razzwan
Copy link

Razzwan commented Feb 20, 2017

The same problem. I had to be used https://github.com/moroshko/react-autosuggest instead.

@jgoux
Copy link
Contributor

jgoux commented Mar 3, 2017

Using something like tether would make sense here.
There is an implementation of the AutoComplete using react-portal + tether here : https://hribb.github.io/react-mdl-extra/?selectedKind=AutoComplete&selectedStory=default
Seems to work great ! 👍

@jannakha
Copy link

jannakha commented Jul 3, 2017

here's a hack, one ugly hack....

  1. Find a div container to which attach scroll listener (window doesn't fire scroll events in this case)
    in componentDidMount() {}
    const div = document.querySelector('div.application-container');
  2. Attach event listener to that container on your component which has autosuggest
    div.addEventListener('scroll', this.handleParentContainerScroll.bind(this));
  3. In event listener, eg handleParentContainerScroll() get ref to AutoComplete component and close it (if user scrolls parent container, they are not interested in auto complete content) - this.refs.authorInput.close();

ugly, but works for now... I tried another AutoComplete component, but it has same issue when it's on a scrollable container

@oliviertassinari
Copy link
Member

Closed by #4783

@adishilo
Copy link

Though this is a bit old thread, We (my friend Guy helped here quite as much) would like to offer the solution we found which is actually offered by the material-ui AutoComplete component.

The AutoComplete component has a property named scrollableContainer which purpose is just that. Define the container component which the pop-over (drop-down) should cling to when it is scrolling. For example, if you set it to the dialog that contains the AutoComplete component - when the dialog scrolls, the drop-down list moves accordingly.
This scrollableContainer prop is an object, and it should be the DOM object of that container. E.g. If you are using React then:

let myDOMobject = ReactDom.findDOMNode(myReactComponent);

where myReactComponent is the container you need the DOM object for.
See also ReactDom.findDOMNode().

@oliviertassinari oliviertassinari added the component: autocomplete This is the name of the generic UI component, not the React module! label Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

8 participants