Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Add md-dropdown-position option to mdAutocomplete. #9774

Merged
merged 1 commit into from
Oct 21, 2016
Merged

Add md-dropdown-position option to mdAutocomplete. #9774

merged 1 commit into from
Oct 21, 2016

Conversation

donmccurdy
Copy link
Contributor

Because obstructions in the viewport (liked fixed-position elements) cannot be automatically detected, allow users to override top/bottom positioning when needed.

Usage:

<md-autocomplete md-items="item in ctrl.querySearch(ctrl.searchText)"
                 md-dropdown-position="bottom"
                 ...

Fixes #9769.

@devversion devversion self-assigned this Oct 6, 2016
@devversion devversion added the needs: review This PR is waiting on review from the team label Oct 6, 2016
Copy link
Member

@devversion devversion left a comment

Choose a reason for hiding this comment

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

This looks good.

Having unit tests for this attribute would be good (Just checking for the top or bottom attribute, to detect the alignment)

@@ -106,7 +106,12 @@ function MdAutocompleteCtrl ($scope, $element, $mdUtil, $mdConstant, $mdTheming,
left = hrect.left - root.left,
width = hrect.width,
offset = getVerticalOffset(),
position = $attrs.mdDropdownPosition,
Copy link
Member

Choose a reason for hiding this comment

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

Can you use $scope.dropdownPosition to support values which can change during runtime?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, so should this be a text binding or two-way?

Copy link
Member

Choose a reason for hiding this comment

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

I think text binding would make more sense here (mdDropdownPosition: '@?')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

styles;
// Automatically determine dropdown placement based on available space in viewport.
Copy link
Member

Choose a reason for hiding this comment

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

While you are at it, can you add an empty line before the comment (just looks better then)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@devversion devversion added the in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs label Oct 6, 2016
@donmccurdy
Copy link
Contributor Author

donmccurdy commented Oct 7, 2016

I am having trouble running the tests — is there documentation somewhere on that? I couldn't find anything in https://github.com/angular/material/blob/master/.github/CONTRIBUTING.md.

When running gulp karma I get:

Cannot load browser "Chrome": it is not registered!

I have at least two versions of Chrome installed. ;)

@devversion
Copy link
Member

I'm sorry, yeah we have not included the chrome karma launcher right now (accidentally) but it will be fixed soon. Try doing npm i karma-chrome-launcher for now, to get everything working.

@donmccurdy
Copy link
Contributor Author

Thanks — I've added a test case now.

Copy link
Member

@devversion devversion left a comment

Choose a reason for hiding this comment

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

Thanks. Please fix those two minor comments, then this should be ready.

'md-items="item in match(searchText)" ' +
'md-item-text="item" ' +
'md-min-length="0" ' +
'md-dropdown-position="' + dropdownPosition +'"' +
Copy link
Member

Choose a reason for hiding this comment

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

Can you just create a scope variable for this, so you can just update the variable later?

<x md-dropdown-position="{{ position }}">
// Then later you could just do the following
scope.$apply('position = "bottom"');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

expect(scrollContainer.style.top).toMatch(/[0-9]+px/);
expect(scrollContainer.style.bottom).toBe('auto');

document.body.removeChild(parent[0]);
Copy link
Member

Choose a reason for hiding this comment

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

Can be simplified to

parent.remove();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@devversion devversion removed the in progress Mainly for in progress PRs, but may be used for issues that require multiple PRs label Oct 7, 2016
@naomiblack naomiblack added the g3: pr This PR was posted by an internal or external product team. label Oct 18, 2016
@devversion
Copy link
Member

@donmccurdy Just looked again on this and it LGTM. Can you please rebase the PR if possible?

@devversion devversion added needs: rebase This PR needs to be rebased on the latest commits from master and conflicts need to be resolved and removed needs: review This PR is waiting on review from the team labels Oct 18, 2016
@ThomasBurleson ThomasBurleson removed the needs: rebase This PR needs to be rebased on the latest commits from master and conflicts need to be resolved label Oct 18, 2016
@ThomasBurleson
Copy link
Contributor

@donmccurdy - after rebase, lgtm.

@ThomasBurleson ThomasBurleson added the needs: rebase This PR needs to be rebased on the latest commits from master and conflicts need to be resolved label Oct 18, 2016
Because obstructions in the viewport (liked fixed-position elements) cannot be automatically detected, allow users to override top/bottom positioning when needed.

Usage:

```html
<md-autocomplete md-items="item in ctrl.querySearch(ctrl.searchText)"
                 md-dropdown-position="bottom"
                 ...
```

Fixes #9769.
@donmccurdy
Copy link
Contributor Author

@devversion @ThomasBurleson Thanks! I've rebased against master. The Travis CI build stalled, though, is that likely to be related to my code?

@ThomasBurleson ThomasBurleson added needs: presubmit and removed needs: rebase This PR needs to be rebased on the latest commits from master and conflicts need to be resolved labels Oct 18, 2016
@ThomasBurleson ThomasBurleson added this to the 1.1.2 milestone Oct 18, 2016
@jelbourn jelbourn merged commit 1ed298b into angular:master Oct 21, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
g3: pr This PR was posted by an internal or external product team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mdAutocomplete menu is above input in unexpected cases
5 participants