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

Add option for aligning autocomplete with right edge of input #13

Merged
merged 2 commits into from Dec 20, 2015

Conversation

dsanders11
Copy link
Contributor

New option to align the autocomplete box with the right edge of the input rather than the left. Useful for inputs close to the right edge of the screen (like the search box in Django admin).

@jpic
Copy link
Member

jpic commented Sep 30, 2015

Pretty cool ! Isn't there any-way autocomplete.js could automatically detect its best positioning ?

@dsanders11
Copy link
Contributor Author

@jpic, that would be pretty nice, but I don't have the time to look into it, unfortunately.

Being able to explicitly define it is nice since automatically detecting doesn't always fit everyone's needs. The parameter could be changed from alignRight to align with a default of auto but also allowing left or right for explicit setting.

@@ -502,6 +509,7 @@ yourlabs.Autocomplete.prototype.show = function(html) {
// Show the inner and outer container only if necessary.
if (!this.box.is(':visible')) {
this.box.css('display', 'block');
this.fixPosition();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like fixPosition() could be called twice here, why is it necessary ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been a few months now so this is hazy in my memory, but I remember there being issues with the box not aligning correctly at times, and adding these two extra calls to fixPosition() resolved the issue and ensured that the box is always in the correct position (been running this for months and the alignment has been solid).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably the display: block changes the position so we have to fix it again, but it would be nice to avoid calling it twice.

@dsanders11
Copy link
Contributor Author

I've added a new commit to this PR after debugging an issue where long text for a text input would push the autocomplete box to the left. This behavior was present on Safari and Chrome, and looks to be because scrollLeft tracks the left edge of the text as it moves left (hidden from view).

jpic added a commit that referenced this pull request Dec 20, 2015
Add option for aligning autocomplete with right edge of input
@jpic jpic merged commit e1536e4 into yourlabs:master Dec 20, 2015
@jpic
Copy link
Member

jpic commented Dec 20, 2015

Ok so this works for me, thanks !!

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

Successfully merging this pull request may close these issues.

None yet

2 participants