-
Notifications
You must be signed in to change notification settings - Fork 903
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(core): Add a TetheredSelect component to tether dropdown to body
- Loading branch information
Justin Reynolds
committed
May 15, 2018
1 parent
5c977ac
commit 185a5f4
Showing
5 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
app/scripts/modules/core/src/presentation/TetheredSelect.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import * as React from 'react'; | ||
import Select from 'react-select'; | ||
import * as TetherComponent from 'react-tether'; | ||
|
||
/* from https://github.com/JedWatson/react-select/issues/810#issuecomment-250274937 **/ | ||
export class TetheredSelect extends Select { | ||
constructor(props: any) { | ||
super(props); | ||
(this as any).renderOuter = this._renderOuter; | ||
} | ||
|
||
public _renderOuter() { | ||
// @ts-ignore - type definitions don't expose renderOuter... | ||
const menu = super.renderOuter.apply(this, arguments); | ||
|
||
// Don't return an updated menu render if we don't have one | ||
if (!menu) { | ||
return null; | ||
} | ||
|
||
/* this.wrapper comes from the ref of the main Select component (super.render()) **/ | ||
const selectWidth = (this as any).wrapper ? (this as any).wrapper.offsetWidth : null; | ||
|
||
return ( | ||
// @ts-ignore - type definitions don't expose renderOuter... | ||
<TetherComponent | ||
classes={{ element: 'layer-high' }} | ||
attachment="top left" | ||
targetAttachment="top left" | ||
constraints={[ | ||
{ | ||
to: 'window', | ||
attachment: 'together', | ||
pin: ['top'], | ||
}, | ||
]} | ||
> | ||
{/* Apply position:static to our menu so that its parent will get the correct dimensions and we can tether the parent */} | ||
<div /> | ||
{React.cloneElement(menu, { style: { position: 'static', width: selectWidth } })} | ||
</TetherComponent> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters