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

Set 'z-index' to render suggestions over descendant elements/components of <MPA> #28

Closed
charlax opened this issue Feb 14, 2018 · 7 comments
Labels

Comments

@charlax
Copy link

charlax commented Feb 14, 2018

Hi there,

First, thank you for this amazing library. Great work there.

My submit button comes from a different component and I'd like the autosuggest component to not know about it. Yet, by default, the suggestions show up below this button:

image

It would be great to have a way to customize the classes of the components inside MUIPlacesAutocomplete, including the suggestions box.

@charlax
Copy link
Author

charlax commented Feb 14, 2018

By the way, you can also see that on this example the Google logo does not show up. Haven't had time to check why yet, that's next on my plate.

@charlax
Copy link
Author

charlax commented Feb 14, 2018

This is probably because you're using react-popper. I might take some inspiration from https://material-ui-next.com/demos/autocomplete/ to do a Paper-based suggestion list.

@Giners
Copy link
Owner

Giners commented Feb 14, 2018

@charlax

Thanks for the positive words. It's good to see/hear that someone is trying to use this library. I'm sure it's rough around the edges/harder to use than others since I'm learning but this feedback definitely helps me grow and make this library better. 😄

I'll look into this and checkout the MUI samples for autocomplete. Is there a code sample/repo that you can provide that quickly shows what you are experiencing?

If you figure out why the Google logo isn't showing up either let me know in another issue.

@charlax
Copy link
Author

charlax commented Feb 15, 2018

Here's how I'm modifying the demo:

% git diff master -- demo/DemoBasic.jsx
diff --git a/demo/DemoBasic.jsx b/demo/DemoBasic.jsx
index e3a3d1b..10d7454 100644
--- a/demo/DemoBasic.jsx
+++ b/demo/DemoBasic.jsx
@@ -1,3 +1,4 @@
+import Button from 'material-ui/Button';
 import React from 'react'
 import Snackbar from 'material-ui/Snackbar'
 import MUIPlacesAutocomplete from './../dist'
@@ -30,6 +31,7 @@ class DemoBasic extends React.Component {
           onSuggestionSelected={this.onSuggestionSelected}
           renderTarget={() => (<div />)}
         />
+      <Button variant="raised" color="secondary" type="submit">Suivant</Button>
         <Snackbar
           onRequestClose={this.onClose}
           anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}

Full file:

import Button from 'material-ui/Button';
import React from 'react'
import Snackbar from 'material-ui/Snackbar'
import MUIPlacesAutocomplete from './../dist'

class DemoBasic extends React.Component {
  constructor() {
    super()

    this.state = { open: false, suggestion: null }

    this.onClose = this.onClose.bind(this)
    this.onSuggestionSelected = this.onSuggestionSelected.bind(this)
  }

  onClose() {
    this.setState({ open: false })
  }

  onSuggestionSelected(suggestion) {
    // Add your business logic here. In this case we simply set our state to show our <Snackbar>.
    this.setState({ open: true, suggestion })
  }

  render() {
    const { open, suggestion } = this.state

    return (
      <div>
        <MUIPlacesAutocomplete
          onSuggestionSelected={this.onSuggestionSelected}
          renderTarget={() => (<div />)}
        />
      <Button variant="raised" color="secondary" type="submit">Suivant</Button>
        <Snackbar
          onRequestClose={this.onClose}
          anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
          autoHideDuration={5000}
          open={open}
          message={suggestion ? (<span>Selected suggestion: {suggestion.description}</span>) : ''}
          style={{ width: '70vw' }}
        />
      </div>
    )
  }
}

DemoBasic.description = 'Basic usage'

export default DemoBasic

Results in:

image

@charlax
Copy link
Author

charlax commented Feb 15, 2018

If I change the Popper' z-index, it works as I'd like to:

image

% git diff master -- src/MUIPlacesAutocomplete.jsx
diff --git a/src/MUIPlacesAutocomplete.jsx b/src/MUIPlacesAutocomplete.jsx
index 7be9108..1618ca0 100644
--- a/src/MUIPlacesAutocomplete.jsx
+++ b/src/MUIPlacesAutocomplete.jsx
@@ -66,7 +66,7 @@ export default class MUIPlacesAutocomplete extends React.Component {
       <Popper
         placement="top-start"
         modifiers={({ inner: { enabled: true } })}
-        style={{ left: 0, right: 0 }}
+        style={{ left: 0, right: 0, zIndex: 1 }}
       >
         {({ popperProps, restProps }) => (
           <div

This is hinted by floating-ui/floating-ui#482

So basically we'd need a way to provide Popper CSS...

@Giners
Copy link
Owner

Giners commented Feb 16, 2018

Awesome repo and info. I have some time this weekend so I am going to look at this issue. My first thoughts are to allow people add styles to <MUIPlacesAutocomplete> via a HOC.

@Giners Giners changed the title Control appearance of suggestions to change their z-index Set 'z-index' to render suggestions over descendant elements/components of <MPA> Feb 16, 2018
Giners added a commit that referenced this issue Feb 16, 2018
Suggestions weren't being rendered over descendant elements/components
to <MUIPlacesAutocomplete>. This was due to a lack of understanding
about how stacking worked. After learning more about it on MDN we set
the 'z-index' on the <Popper> which provides the modality for our
rendered suggestions. This fixes the problem as descendant
elements/components will be in the same stacking context as <MPA>.

We provide a default 'z-index' of 1. Looking forward we ought to allow
people to customize the 'z-index' further. Rather than solving that
issue in this commit we will do so in another that allows for fine
granular control over <Popper> as well as the other components that
<MPA> composes.
	modified:   src/MUIPlacesAutocomplete.jsx
	modified:   test/test.jsx
@Giners Giners added the bug label Feb 16, 2018
@Giners
Copy link
Owner

Giners commented Feb 16, 2018

@charlax

I've renamed this issue and gave it a label of 'bug' to isolate the issue of suggestions not rendering over descendant elements/components vs. providing fine grained control over the appearance/behavior of the elements/components that <MUIPlacesAutocomplete> composes. I've filed a task for providing fine grained control here: #29.

I've got a PR to fix the issue of the suggestions not rendering over descendant elements/components here: #30. This will unblock you and others while I provide a solution for fine grained control.

@Giners Giners closed this as completed in 92b4e3e Feb 16, 2018
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

2 participants