-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* inputpopover component * popover provides attached styles now * fullWidth
- Loading branch information
1 parent
496a3e6
commit a0640be
Showing
8 changed files
with
124 additions
and
17 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
@import 'popover'; | ||
@import 'popover_title'; | ||
@import 'popover_footer'; | ||
@import 'input_popover'; |
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,5 @@ | ||
.euiInputPopover { | ||
&.euiInputPopover--fullWidth { | ||
max-width: 100%; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classnames from 'classnames'; | ||
import tabbable from 'tabbable'; | ||
|
||
import { EuiFocusTrap } from '../focus_trap'; | ||
import { EuiPopover, EuiPopoverPropTypes } from './popover'; | ||
import { cascadingMenuKeyCodes } from '../../services'; | ||
|
||
export const EuiInputPopover = ({ | ||
children, | ||
className, | ||
fullWidth, | ||
input, | ||
popoverZIndex, | ||
...props | ||
}) => { | ||
const [inputEl, setInputEl] = useState(); | ||
const [inputElWidth, setInputElWidth] = useState(); | ||
const [panelEl, setPanelEl] = useState(); | ||
const inputRef = node => setInputEl(node); | ||
const panelRef = node => setPanelEl(node); | ||
const setPanelWidth = () => { | ||
if (panelEl && inputElWidth) { | ||
panelEl.style.width = `${inputElWidth}px`; | ||
} | ||
}; | ||
useEffect(() => { | ||
if (inputEl) { | ||
const width = inputEl.getBoundingClientRect().width; | ||
setInputElWidth(width); | ||
setPanelWidth(); | ||
} | ||
}, [inputEl]); | ||
useEffect(() => { | ||
setPanelWidth(); | ||
}, [panelEl]); | ||
const onKeyDown = e => { | ||
if (e.keyCode === cascadingMenuKeyCodes.TAB) { | ||
const tabbableItems = tabbable(panelEl).filter(el => { | ||
return ( | ||
[...el.attributes].map(el => el.name).indexOf('data-focus-guard') < 0 | ||
); | ||
}); | ||
if ( | ||
tabbableItems.length && | ||
tabbableItems[tabbableItems.length - 1] === document.activeElement | ||
) { | ||
props.closePopover(); | ||
} | ||
} | ||
}; | ||
const classes = classnames( | ||
'euiInputPopover', | ||
{ | ||
'euiInputPopover--fullWidth': fullWidth, | ||
}, | ||
className | ||
); | ||
return ( | ||
<EuiPopover | ||
ownFocus={false} | ||
button={input} | ||
buttonRef={inputRef} | ||
panelRef={panelRef} | ||
className={classes} | ||
{...props}> | ||
<EuiFocusTrap clickOutsideDisables={true}> | ||
<div onKeyDown={onKeyDown}>{children}</div> | ||
</EuiFocusTrap> | ||
</EuiPopover> | ||
); | ||
}; | ||
|
||
const { button, buttonRef, ...propTypes } = EuiPopoverPropTypes; | ||
EuiInputPopover.propTypes = { | ||
fullWidth: PropTypes.bool, | ||
input: EuiPopoverPropTypes.button, | ||
inputRef: EuiPopoverPropTypes.buttonRef, | ||
...propTypes, | ||
}; | ||
|
||
EuiInputPopover.defaultProps = { | ||
anchorPosition: 'downLeft', | ||
attachToAnchor: true, | ||
display: 'block', | ||
fullWidth: false, | ||
panelPaddingSize: 's', | ||
}; |
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