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

Fix the align of the dropdown when expanded in ClayDropdown | Fixes #452 #482

Merged
merged 2 commits into from
Jan 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 29 additions & 22 deletions packages/clay-dropdown/src/ClayDropdownBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ import templates from './ClayDropdownBase.soy.js';
* Implementation of the base for Metal Clay Dropdown.
*/
class ClayDropdownBase extends Component {
/**
* @inheritDoc
*/
attached() {
this.refs.portal.on('rendered', this.handleRenderedPortal_.bind(this));
}

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -85,6 +92,28 @@ class ClayDropdownBase extends Component {
this.emit('itemClicked', event);
}

/**
* Handle when the lifecycle `rendered` is called in ClayPortal.
* @protected
*/
handleRenderedPortal_() {
if (this.expanded && this.alignElementSelector_) {
// eslint-disable-next-line
let alignElement = this.element.querySelector(
this.alignElementSelector_
);
if (alignElement) {
let bodyElement = this.refs.portal.refs.menu;

this.alignedPosition_ = Align.align(
bodyElement,
alignElement,
Align.BottomLeft
);
}
}
}

/**
* Handles Search in Dropdown.
* @param {!Event} event
Expand Down Expand Up @@ -132,28 +161,6 @@ class ClayDropdownBase extends Component {
});
}

/**
* Synchronization logic for `expanded` state.
* @param {boolean} expanded
*/
syncExpanded(expanded) {
if (expanded && this.alignElementSelector_) {
// eslint-disable-next-line
let alignElement = this.element.querySelector(
this.alignElementSelector_
);
if (alignElement) {
let bodyElement = this.refs.portal.refs.menu;

this.alignedPosition_ = Align.align(
bodyElement,
alignElement,
Align.BottomLeft
);
}
}
}

/**
* Toggles the dropdown, closing it when open or opening it when closed.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ exports[`ClayActionsDropdown should render an expanded action dropdown 1`] = `
</svg>
</button>
</div>
<div class="dropdown-menu show" ref="menu" style="top: 0px; left: 0px;">
<div class="dropdown-menu show" ref="menu">
<ul class="list-unstyled">
<li>
<a class=" dropdown-item" href="#1">Edit</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ exports[`ClayDropdown should render an expanded dropdown 1`] = `
</svg>
</button>
</div>
<div class="dropdown-menu show" ref="menu" style="top: 0px; left: 0px;">
<div class="dropdown-menu show" ref="menu">
<ul class="list-unstyled">
<li>
<a class=" dropdown-item" href="item1url">Item 1</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`ClayDropdownBase should close dropdown 1`] = `
<div class="dropdown">
<button aria-expanded="false" aria-haspopup="true" aria-label="toggle" class="dropdown-toggle btn btn-unstyled" type="button">Trigger</button>
</div>
<div class="dropdown-menu" ref="menu" style="top: 0px; left: 0px;">
<div class="dropdown-menu" ref="menu">
<ul class="list-unstyled">
<li>
<a class=" dropdown-item" href="item1url">Item 1</a>
Expand Down