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

Documentation needs instructions on how to theme #400

Open
kylegoetz opened this issue Jul 7, 2017 · 10 comments
Open

Documentation needs instructions on how to theme #400

kylegoetz opened this issue Jul 7, 2017 · 10 comments

Comments

@kylegoetz
Copy link

kylegoetz commented Jul 7, 2017

The demos all have arcane CSS rules with no documentation. I see in the dist there's a theme.js, but I can't figure out how to import it and use it. So right now because of probably some copy/paste error from one of the demo CSS files to my own CSS the appearance of the suggestions is not aligned properly. Would be nice to know how I could import ./node_modules/react-autosuggest/dist/theme.js but can't find it in the documentation. So I think this counts as a bug I guess.

I want to do this because with the default create-react-app and then adding the autosuggest straight out of a demo (modifying the render item function) results in this, which as you can see does not line up correctly. The container of all of it has text-align: center. This appears to, without any custom styling, center only the search bar but not the results. CSS is copied and pasted straight out of one of the demos.

screen shot 2017-07-06 at 22 20 50

@kylegoetz
Copy link
Author

kylegoetz commented Jul 7, 2017

Not sure what to do about this issue, whether to close this and create a new, or just leave a new comment, but here's what I discovered:

Styling applied to the parent container will only be applied to the INPUT but not to the DIV that contains the suggestions. So if you have a parent DIV with text-align: center, it will center the INPUT but not the contents of DIV (I think this is because a block-level element isn't supposed to be moved like that with text-align: center).

My provisional solution was to create a parent DIV that exists solely to contain the and style it position: absolute; left: 25%; width: 50%; and then to the .react-autosuggest__suggestions-container--open change width to 100% and give a padding: 0 20px; and then to .react-autosuggest__input change width to 100% and leave padding at the 10px 20px that you see in the demos. It works for my purposes, but might not for anyone else.

So there needs to be some fix for this. If I have time, I'll work on it, but I have a newborn daughter and am the primary caregiver, so it might take a few years :)

@nodediggity
Copy link

+1

I can't for the life of me understand themes with this plugin

@oliviertassinari
Copy link

oliviertassinari commented Jul 24, 2017

You can find a theme integration example on the Material-UI documentation.

@rishabkdoshi
Copy link

+1, need better documentation/examples that use .css instead of .less to style

@kimhjona
Copy link

PSA: url for Material-UI example is now here

@oliviertassinari
Copy link

@kimhjona Right, sorry, I have updated the link (we just published a new version based on next.js).

@kimhjona
Copy link

ah, found it. link for those looking for the source code

Repository owner deleted a comment Aug 25, 2017
@James-E-Adams
Copy link

James-E-Adams commented Jan 5, 2018

Hi @moroshko! I'm also struggling to work out how to override default themes.

Here's what I'm doing at the moment:

import Autosuggest from 'react-autosuggest';
import { defaultTheme } from 'react-autosuggest/dist/theme';

    <Autosuggest
      //misc extra props I've cut out for brevity
      theme={{
        ...defaultTheme,
        ...{
              container: {
                ...defaultTheme.container,
                display: 'visible',
                width: '340px',
              },
              //more overrides
            }
      }}
    />

The goal is to keep the default theming for container, as well as add some overrides. Is that possible in someway like this?

Edit: From what I can tell, you're using this format from react-themeable:

Global CSS

.MyComponent__foo { color: red; }
.MyComponent__foo:hover { color: green; }
.MyComponent__bar { color: blue; }
const theme = {
  foo: 'MyComponent__foo',
  bar: 'MyComponent__bar'
};
...
<MyComponent theme={theme} />

But I haven't thought of an elegant way of including the existing default theme for container as well as providing some extra styles.

@taykcrane
Copy link

@kylegoetz If I read your comment correctly, you created a div just to contain the input? How did you do this... I desperately need to wrap the Autosuggest input in a container div for CSS reasons, but cannot figure out how to do this. The parent div that Autosuggest creates contains everything, including the suggestions list. I need a container specifically just for the input field.

Let me know what you did, thanks in advance.

@kylegoetz
Copy link
Author

@taykcrane It's been a while, but I think I just wrote my React code to be

<div class="who-cares">
    <Autosuggest ... />
</div>

and then

.who-cares {
    position: absolute; 
    left: 25%; 
    width: 50%; 
}
.react-autosuggest__suggestions-container--open {
    width: 100%;
    padding: 0 20px;
}
.react-autosuggest__input {
    width: 100%;
    padding: 10px 20px;
}

possibly for styling the .react-autosuggest stuff I had to use !important to override. Maybe I made that css .who-cares .react-autosuggest... instead and didn't have to use the !important.

It was for a work thing (client demo) and I ended up solving it and never thinking about it again. Don't have the code around now, though. Sorry. Good luck!

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

No branches or pull requests

7 participants