awesomplete icon indicating copy to clipboard operation
awesomplete copied to clipboard

scroll bar‏ for the popup menu

Open Mishary457 opened this issue 8 years ago • 16 comments

Hello all, Thanks for the tool. It is very useful. Is it possible to add a scroll bar to the suggested list if I want to show all the suggestions. Let's say I set the maxItems to really big number, and I don't want to have the drop down menu to be very long list without a scroll bar to control the appearance and to show all the suggestions that match with the user input while typing. Your answer is appreciated.

Mishary457 avatar Mar 17 '16 19:03 Mishary457

thanks for Lea Verou ✿ http://lea.verou.me ✿ @leaverou @vlazar vlazar I checked the developer tools, and found that it is awesomplete class. So, I checked awesomplete.css and found the following code. then, I added this line : overflow: auto; div.awesomplete { display: inline-block; position: relative; overflow: auto; } It worked fine. however, one thing is that once I click on the down arrow in the popup menu, it doesn't go down down with the highlighted option. So, I have to use the scroll bar.

Mishary457 avatar Mar 18 '16 22:03 Mishary457

@vlazar To explain what's happening a bit more: The element doesn't scroll into view when highlighted. Do you think there's an easy way for him to work around it? Should we address this use case in the Awesomplete core is it too niche? Thoughts?

LeaVerou avatar Mar 19 '16 23:03 LeaVerou

@vlazar there is one more issue. this command " sort: Array.prototype.sort(), " is not supported firefox

Mishary457 avatar Mar 20 '16 16:03 Mishary457

I think it's somewhat relate to supporting <select> element out of the box. It makes more sense to have scroll for select-like autocomplete, but it can be useful to support it for general case too.

vlazar avatar Mar 21 '16 06:03 vlazar

thanks,@leaverou and @vlazar ,for replying. One more issue is that when you submit your form and look at the results. Then, click back button. The popup doesn't work anymore.

Mishary457 avatar Mar 21 '16 09:03 Mishary457

If I understand the question correctly, this behavior is already pretty easy to achieve using the awesomplete-highlight event:

input.addEventListener('awesomplete-highlight', function(evt){
  if(input.querySelector('[aria-selected=true]')) element.scrollIntoView(false);
});

TxHawks avatar Mar 21 '16 23:03 TxHawks

The "scroll to selected item in dropdown" functionality can be achieved easily by adding one line to the goto method:

goto: function (i) {
    var lis = this.ul.children;

    if (this.selected) {
      lis[this.index].setAttribute("aria-selected", "false");
    }

    this.index = i;

    if (i > -1 && lis.length > 0) {
      lis[i].setAttribute("aria-selected", "true");
>     lis[i].scrollIntoView(false);
      this.status.textContent = lis[i].textContent;
    }

    Bliss.fire(this.input, "awesomplete-highlight");
  }

fractaledmind avatar Mar 23 '16 20:03 fractaledmind

We can't do this blindly though, we'd need to check if the container is actually scrollable. We don't want the entire page to jump around.

LeaVerou avatar Mar 28 '16 15:03 LeaVerou

Does scrollIntoView(false) has some quirks?

vlazar avatar Mar 28 '16 15:03 vlazar

"We don't want the entire page to jump around."

Found a fix for this issue. This is how my goto method looks like

  goto: function (i) {
	var lis = this.ul.children;

	if (this.selected) {
		lis[this.index].setAttribute("aria-selected", "false");
	}

	this.index = i;
	var doc = document.documentElement;
	var top = (window.pageYOffset || doc.scrollTop)  - (doc.clientTop || 0);
	if (i > -1 && lis.length > 0) {
		lis[i].setAttribute("aria-selected", "true");
		lis[i].scrollIntoView(false);
		window.scrollTo(0, top);
		this.status.textContent = lis[i].textContent;
		// scroll to highlighted element in case parent's height is fixed 
		this.ul.scrollTop = lis[i].offsetTop - this.ul.clientHeight + lis[i].clientHeight;

		$.fire(this.input, "awesomplete-highlight", {
			text: this.suggestions[this.index]
		});
	}
}

Btw, thanks for this cool plugin.

Dejard avatar Jan 19 '17 18:01 Dejard

What if:

new Awesomplete(inputReference, {
	maxItems: 10500,
	...
});
.awesomplete > ul {
    max-height: 410px;
    overflow-y: auto;
}

?

c80609a avatar May 24 '17 11:05 c80609a

Further the comment above, the following also works very well: .awesomplete > ul { max-height: 80vh; overflow-y: auto; }

MrBertie avatar Apr 09 '18 10:04 MrBertie

I've been using the method proposed by c80609a above (set a max height and overflow-y to auto), and it works other than one huge problem: if I click on the scrollbar with my mouse, it instantly closes the dropdown, so I can't actually use the mouse to click on the scrollbar at all. I assume this is because there's a click event Awesomplete puts on the dropdown that always closes the dropdown no matter what else happens.

My only idea was to use the awesomplete-close event to somehow check if the click target was the scrollbar and if so, prevent closing. Unfortunately, I couldn't find anyway to prevent closing the dropdown in the close event (and never even got far enough to see if I could detect the scrollbar as the target).

Does anyone have any idea how to solve this issue?

dillydadally avatar May 16 '18 04:05 dillydadally

What version is your browser?

Try Selectize, https://github.com/frappe/frappe/pull/4574

c80609a avatar May 16 '18 14:05 c80609a

I'm using Chrome Version 66.0.3359.139 (Official Build) (64-bit). I hesitate to change my implementation too much at this point. Awesomplete is deeply ingrained into my app and I've been able to make it function literally perfect other than this single remaining issue.

I did a very simple implementation in jsfiddle and found out that this same behavior is not happening outside my app, so I assume that I must be causing it somehow. I'm now combing through my code to see what could be causing it and will report back.

dillydadally avatar May 16 '18 15:05 dillydadally

I've discovered the issue. It appears to be a conflict between Awesomplete and Jquery UI's dialog widget. If I create an awesomplete on my page, I can click and scroll, but if I create an Awesomplete in a dialog window created by jquery ui, it will close the dropdown when you click on the scrollbar.

I know it's a long shot, but does anyone have any ideas why this might be happening?

dillydadally avatar May 16 '18 17:05 dillydadally