bootstrap-autocomplete icon indicating copy to clipboard operation
bootstrap-autocomplete copied to clipboard

Allowing Auto Width to Search Result Dropdown

Open github5775 opened this issue 5 years ago • 4 comments

Thank you for this control. I noticed that the width of the search result dropdown was limited, and I needed to allow the user to see the complete results, so I removed the width setting. You may want to add this as an option.

Original:
this.dd.css({ top: pos.top + this.$el.outerHeight(), left: pos.left, width: this._$el.outerWidth() });

With Removed Width Setting: this.dd.css({ top: pos.top + this.$el.outerHeight(), left: pos.left });

github5775 avatar May 31 '19 07:05 github5775

Thanks @github5775 I'll keep this planned for a future release! :+1:

xcash avatar May 31 '19 10:05 xcash

Just hook the div inserting like that:

var styleChangedCallback = function (mutations) {
	var newWidth = mutations[0].target.style.width;
	if (newWidth !== '100%'){			
		$('.bootstrap-autocomplete.dropdown-menu').css('width', '100%');
	}
}
document.addEventListener("DOMNodeInserted", function(evt) {
if (evt.target.className === "bootstrap-autocomplete dropdown-menu"){
	var observer = new MutationObserver(styleChangedCallback);
	observer.observe(evt.target, {
		attributes: true,
		attributeFilter: ['style'],
	});
}
}, false);

dvd73 avatar Dec 04 '19 14:12 dvd73

The autocomplete.dd.shown event may also be used to bypass this, but that's hacky. For instance:

$(document).on('autocomplete.dd.shown', '#id_q', function(e){
    $('.bootstrap-autocomplete.dropdown-menu').css('width', 'calc(100% - 32px');
});

loic-bellinger avatar May 05 '20 13:05 loic-bellinger

Used this as a work-around : .bootstrap-autocomplete.dropdown-menu{ width: auto !important; }

CommittedSpin avatar Nov 25 '20 00:11 CommittedSpin