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

Components: Center all popovers relative anchor parent #3958

Merged
merged 2 commits into from
Jan 3, 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
34 changes: 21 additions & 13 deletions components/dropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,30 @@ class Dropdown extends Component {
contentClassName,
expandOnMobile,
} = this.props;

const args = { isOpen, onToggle: this.toggle, onClose: this.close };

return (
<div className={ className } ref={ this.bindContainer }>
{ renderToggle( args ) }
<Popover
className={ contentClassName }
isOpen={ isOpen }
position={ position }
onClose={ this.close }
onClickOutside={ this.clickOutside }
expandOnMobile={ expandOnMobile }
>
<FocusManaged>
{ renderContent( args ) }
</FocusManaged>
</Popover>
{ /**
* This seemingly redundant wrapper node avoids root return
* element styling impacting popover positioning.
*/ }
<div>
{ renderToggle( args ) }
<Popover
className={ contentClassName }
isOpen={ isOpen }
position={ position }
onClose={ this.close }
onClickOutside={ this.clickOutside }
expandOnMobile={ expandOnMobile }
>
<FocusManaged>
{ renderContent( args ) }
</FocusManaged>
</Popover>
</div>
</div>
);
}
Expand Down
17 changes: 2 additions & 15 deletions components/popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ const FocusManaged = withFocusReturn( ( { children } ) => children );

const { ESCAPE } = keycodes;

/**
* Offset by which popover should adjust horizontally to account for tail.
*
* @type {Number}
*/
const ARROW_OFFSET = 20;

/**
* Name of slot in which popover should fill.
*
Expand Down Expand Up @@ -194,14 +187,8 @@ class Popover extends Component {
popover.style.bottom = 'auto';
popover.style.right = 'auto';

if ( isRight ) {
popover.style.left = rect.left + ARROW_OFFSET + 'px';
} else if ( isLeft ) {
popover.style.left = ( rect.right - ARROW_OFFSET ) + 'px';
} else {
// Set popover at parent node center
popover.style.left = Math.round( rect.left + ( rect.width / 2 ) ) + 'px';
}
// Set popover at parent node center
popover.style.left = Math.round( rect.left + ( rect.width / 2 ) ) + 'px';

// Set at top or bottom of parent node based on popover position
popover.style.top = rect[ yAxis ] + 'px';
Expand Down
2 changes: 2 additions & 0 deletions components/popover/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
left: 50%;

&:not(.is-mobile) {
margin-left: 2px;

&:before {
border: 8px solid $light-gray-500;
}
Expand Down