Giter VIP home page Giter VIP logo

Comments (14)

vvo avatar vvo commented on May 12, 2024 1

IMHO calculating CSS styles internally is a bad design choice, and not exposing those options is a bigger one.

Hey hi @dhavalgshah, thanks for the extensive feedback it's important for us. Since this issue was pretty old it's not easy to immediately get what we should do here.

Do you think you could summarise the current problem in a concrete way and propose a few solutions and implementations ideas as to fix this problem? Thanks.

from autocomplete.

FezVrasta avatar FezVrasta commented on May 12, 2024 1

That looks good to me, I'll try to work on it this week and I'll reach to you if I need any guidance.

from autocomplete.

redox avatar redox commented on May 12, 2024

At least definitely something we need to document. I'm used to play with margin-left: -XXXpx to align on the left but I understand it can be confusing. Regarding the auto alignment, it's not that simple because a lot of searchbars have padding, arounded corners, etc... but I get your point.

from autocomplete.

iafan avatar iafan commented on May 12, 2024

Consider this layout as an example (Docsearch search box in the top right corner): https://serge.io/ — I don't think there's a way to position this correctly using CSS-based absolute positioning, unfortunately.

from autocomplete.

iafan avatar iafan commented on May 12, 2024

Oh, you meant using margin — that would actually work. Thanks!

from autocomplete.

redox avatar redox commented on May 12, 2024

Oh, you meant using margin — that would actually work. Thanks!

Yes, that's the quick fix :)

But having an option (or a CSS class) letting the user decide whether it's left or right aligned by default make sense.

from autocomplete.

dhavalgshah avatar dhavalgshah commented on May 12, 2024

Hi @redox any update on this issue?

This is really a huge problem for the responsive web.

Either we should write fluid CSS and use class names to determine the view or have all the internal CSS styles that are being calculated exposed in options. Either of these approaches doesn't seem to be incompatible in either of the flavors you're offering.

Aside from one example mentioned by @iafan here are few other scenarios:

  1. When you have search-input in the center bottom and want results to show above that input.
  2. When search input is in either of the sides (left/right) and you want dropdown to appear beside it (left or right of the input)
  3. When search input is on an overlay that takes the entire screen and you want the dropdown to align center and have a wider width.

IMHO calculating CSS styles internally is a bad design choice, and not exposing those options is a bigger one.

from autocomplete.

FezVrasta avatar FezVrasta commented on May 12, 2024

Would you accept a PR to integrate Popper in this library to better position the dropown?

from autocomplete.

redox avatar redox commented on May 12, 2024

@francoischalifour what do you think? Regarding the "next" version you're working on.

from autocomplete.

francoischalifour avatar francoischalifour commented on May 12, 2024

Autocomplete.js v0 (current version) is not in active development, so we won't invest much more in new features for that version. Sending a PR now won't be a great investment of your time @FezVrasta.

Integrating Popper as is in Autocomplete.js might not be a viable solution for us because we want the next version of the library to be as lightweight as possible. According to the current Popper UMD build, it would be an additional 8.2KB. We'd need to investigate to see if this size cost is justified.

In the current Autocomplete.js v1 alpha (in early development), we support this feature with the dropdownAlignment option. If ever the website imposes some CSS constraints, you can use getDropdownPosition to adjust the computed position of the dropdown on screen with JavaScript. This allows for instance to position the dropdown differently whether you're on desktop, tablet or mobile via getBoundingClientRect information.

This API is still subject to change, but in my experience that was the best compromise in terms of flexibility and bundle size. If you have time @FezVrasta, I would love it if you try this alpha version and give us feedback if this positioning API is flexible enough for your use cases. If not, we might revisit this API or consider depending on an external dependency like Popper.

from autocomplete.

FezVrasta avatar FezVrasta commented on May 12, 2024

My case was way trickier than the one described by OP, I had the dropdown inside a scrollable, fixed element, inside a scrollable body.

I had to change the layout of my app to make it work, but now I have this other issue where not the whole dropdown fits in the viewport and gets cut. This can be fixed with 450 bytes of custom Popper modifier.

image

From what I can see, @francoischalifour/autocomplete.js is 52.5 kB, so the 8 kB of popper-lite don't look too bad in my opinion, considered it would cover all the possible use cases and situations without additional maintenance required.

Alternatively, you could make Popper an optional dependency, so that who needs it can easily plug it into your code.

from autocomplete.

francoischalifour avatar francoischalifour commented on May 12, 2024

My case was way trickier than the one described by OP, I had the dropdown inside a scrollable, fixed element, inside a scrollable body.

By default, the next version injects the dropdown in the body, not in the search box container. Given that you can position it with JavaScript, that would be the most flexible solution AFAIK.

From what I can see, @francoischalifour/autocomplete.js is 52.5 kB, so the 8 kB of popper-lite don't look too bad in my opinion, considered it would cover all the possible use cases and situations without additional maintenance required.

As the current state, yes, because we depend on Downshift in this prototype, but we plan to get rid of this dependency when releasing stable, so size will go down.

Alternatively, you could make Popper an optional dependency, so that who needs it can easily plug it into your code.

I'm still open to suggestions because positioning is a field that remains to be explored in the next version.

At this stage, I think the best way would be to try integrating Popper to the alpha version to see if that would be a good fit. Would you like to send a PR proposal there? I can guide you through how the project works if needed.

from autocomplete.

FezVrasta avatar FezVrasta commented on May 12, 2024

Here's the PR:
francoischalifour#14

from autocomplete.

francoischalifour avatar francoischalifour commented on May 12, 2024

Autocomplete v0 has been in low maintenance mode for a few years and we just released Autocomplete v1 so I'm closing this.

Resources

from autocomplete.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.