Skip to content

Commit

Permalink
fix: Position component (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo authored Apr 29, 2020
1 parent 66453b6 commit 81940ec
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 8 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions packages/fuselage/src/components/Box/Position/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const left = (left) => ({ left });
const right = (right) => ({ right });

function getOffset(el) {
return el.getBoundingClientRect();
const { top, right, bottom, left, width, height, x, y } = el.getBoundingClientRect();
return { top, right, bottom, left, width, height, x, y };
}

const getVertical = (anchorPosition, elementPosition, placement = 'bottom') => {
Expand All @@ -33,9 +34,9 @@ const getVertical = (anchorPosition, elementPosition, placement = 'bottom') => {
const getHorizontal = (anchorPosition, elementPosition, placement = 'right') => {
switch (placement) {
case 'right':
return anchorPosition.right + elementPosition.width > window.innerWidth ? right(0) : left(anchorPosition.right);
return anchorPosition.left + elementPosition.width > window.innerWidth ? right(0) : left(anchorPosition.left);
case 'left':
return anchorPosition.left - elementPosition.width > 0 ? left(anchorPosition.left - elementPosition.width) : left(0);
return anchorPosition.right - elementPosition.width > 0 ? left(anchorPosition.right - elementPosition.width) : left(0);
case 'center':
return left(anchorPosition.left + anchorPosition.width / 2 - elementPosition.width / 2 >= 0 ? anchorPosition.left + anchorPosition.width / 2 - elementPosition.width / 2 : 0);
default:
Expand All @@ -58,7 +59,6 @@ const throttle = (func, limit) => {
export const Position = ({ anchor, width = 'stretch', style, className, children, placement = 'bottom center'/* , offset*/ }) => {
const [position, setPosition] = useState();
const ref = useRef();

const resizer = useRef();

const { offsetWidth } = anchor.current || {};
Expand Down
7 changes: 5 additions & 2 deletions packages/fuselage/src/components/Menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const mapOptions = (options) => Object.entries(options).map(([value, { label }])

export const Menu = ({
options,
optionWidth = '240px',
optionWidth,
placement = 'bottom right',
...props }) => {
const mappedOptions = mapOptions(options);
Expand All @@ -27,7 +27,10 @@ export const Menu = ({
});

const ref = useRef();
const onClick = useCallback(() => ref.current.focus() & show(), [show]);
const onClick = useCallback(() => {
ref.current.focus() & show();
ref.current.classList.add('focus-visible');
}, [show]);

const handleSelection = useCallback((args) => {
menuAction(args, options);
Expand Down
3 changes: 1 addition & 2 deletions packages/fuselage/src/components/Options/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export const OptionAvatar = React.memo(({ id, value, children: label, focus, sel

export const Options = React.forwardRef(({
maxHeight = '144px',
width = '240px',
multiple,
renderEmpty: EmptyComponent = Empty,
options,
Expand All @@ -67,7 +66,7 @@ export const Options = React.forwardRef(({
<Tile padding='x8' elevation='2'>
<Scrollable vertical smooth>
<Margins blockStart='x4'>
<Tile ref={ref} elevation='0' padding='none' width={width} maxHeight={maxHeight} onMouseDown={prevent} onClick={prevent} is='ol' aria-multiselectable={multiple} role='listbox' aria-multiselectable='true' aria-activedescendant={options && options[cursor] && options[cursor][0]}>
<Tile ref={ref} elevation='0' padding='none' maxHeight={maxHeight} onMouseDown={prevent} onClick={prevent} is='ol' aria-multiselectable={multiple} role='listbox' aria-multiselectable='true' aria-activedescendant={options && options[cursor] && options[cursor][0]}>
{!options.length && <EmptyComponent/>}
{optionsMemoized}
</Tile>
Expand Down

0 comments on commit 81940ec

Please sign in to comment.