Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Typeahead popup position #3874

Closed
wants to merge 10 commits into from

Conversation

davidrus
Copy link

Append-to-body dropdown position

Add support for typeahead-dropdown position after scroll and resize events.

Scenario 1

  • Type some text into input (show dropdown appended to body)
  • Scroll down
  • We need dropdown in right place after input

Scenario 2

  • Type some text into input (show dropdown appended to body)
  • Resize after breakpoint in media query (change position of input)
  • We need dropdown in right place after input

Thanks

// bind events only if appendToBody params exist - performance feature
if ( appendToBody ) {
angular.element( $window ).bind( 'resize', fireRecalculating );
angular.element( document.body ).bind( 'scroll', fireRecalculating );
Copy link
Contributor

Choose a reason for hiding this comment

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

These bindings should be throttled.

Also you can use $document.find('body') instead.

var body = angular.element(document.body);

// Set body height to allow scrolling
body.css({height:"10000px"});
Copy link
Contributor

Choose a reason for hiding this comment

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

Use single quotes

@davidrus
Copy link
Author

Thanks for comments, all done. Travis OK

@davidrus
Copy link
Author

davidrus commented Jul 2, 2015

Any news for this enhancement?

// bind events only if appendToBody params exist - performance feature
if ( appendToBody ) {
angular.element( $window ).bind( 'resize', fireRecalculating );
$document.find( 'body' ).bind( 'scroll', fireRecalculating );
Copy link
Contributor

Choose a reason for hiding this comment

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

Both these event listeners need to be throttled - the resize and scroll events both fire often.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, a debounce on each of the event listeners would be better, since we only care about the trailing trigger of the event.

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove spaces just after ( and just before )

@davidrus
Copy link
Author

davidrus commented Jul 3, 2015

I added debounced execution of event logic and support for hiding popup if scroll & resize is "in progress".

@@ -170,6 +171,52 @@ angular.module('ui.bootstrap.typeahead', ['ui.bootstrap.position', 'ui.bootstrap
});
};

// bind events only if appendToBody params exist - performance feature
if ( appendToBody ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove spaces in between ( and )


// Debounced executing recalculate after events fired
timeoutEventPromise = $timeout(function () {

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this line

@davidrus
Copy link
Author

davidrus commented Jul 5, 2015

Done

@wesleycho
Copy link
Contributor

Adding a comment here for better visibility - there are multiple PRs involving positioning, so I am going to look into seeing if there is a better way of handling it inside $position instead.

@wesleycho
Copy link
Contributor

This PR looks safe to merge, although I think the debounce should be split off into a separate service - I'm inclined to hold off until this is done.

I could merge this in now, or wait until the debounce is split off into a service - the benefit of holding off would be that debounce would be available as a utility injectable for anyone who needs it, but it does put some more burden on you.

What are your thoughts?

@davidrus
Copy link
Author

davidrus commented Jul 6, 2015

OK, the idea of separate debounce in service is good. But I think this should be in separate PR. I can write this after merge this PR.

@davidrus
Copy link
Author

davidrus commented Jul 8, 2015

Only for my information: when are you planning to merge it into production?

@wesleycho
Copy link
Contributor

I think the debounce should be split off here - can you update your PR with that change?

@wesleycho
Copy link
Contributor

Actually, scratch my comment - I will merge this in today, and work can be done to split the debounce to a separate component after.

@wesleycho wesleycho modified the milestones: 0.13.1 (Performance), Backlog Jul 19, 2015
@wesleycho wesleycho closed this in 86bfec1 Jul 19, 2015
@davidrus davidrus deleted the typeahead-popup-position branch July 28, 2015 11:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants