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

making popper dissapear on esc click #1869

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
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export default function Version(): JSX.Element {
borderRadius: '5px',
boxShadow: 2,
marginLeft: '15px',
zIndex: 300,
padding: '10px',
'& a': {
color: (theme: Theme) =>
Expand Down Expand Up @@ -84,7 +83,7 @@ export default function Version(): JSX.Element {
</SvgIcon>
</IconButton>

<Popper sx={{ zIndex: '150' }} open={open} anchorEl={anchorEl} placement="right-end" container={mapElem}>
<Popper open={open} anchorEl={anchorEl} placement="right-end" onClose={handleClickAway} container={mapElem}>
<Paper sx={sxClasses.versionInfoPanel}>
<Typography sx={sxClasses.versionsInfoTitle} component="h3">
{t('appbar.version')}
Expand Down
11 changes: 9 additions & 2 deletions packages/geoview-core/src/core/components/common/layer-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ const LayerListItem = memo(function LayerListItem({ isSelected, layer, onListIte
const sxClasses = getSxClasses(theme);
const { t } = useTranslation<string>();

const isDisabled = layer.numOffeatures === 0;
const isDisabled = layer?.numOffeatures === 0 || layer?.features === null;

const isLoading =
layer?.numOffeatures === 0 ||
layer?.features === null ||
layer.queryStatus === 'processing' ||
layer.layerStatus === 'loading' ||
layer.layerStatus === 'processing';

const renderLayerIcon = () => {
switch (layer.layerStatus) {
Expand Down Expand Up @@ -126,7 +133,7 @@ const LayerListItem = memo(function LayerListItem({ isSelected, layer, onListIte
<ListItemButton
selected={isSelected}
// disable when layer features has null value.
disabled={layer?.numOffeatures === 0 || layer?.features === null}
disabled={isDisabled || isLoading}
onClick={() => onListItemClick(layer)}
>
{renderLayerIcon()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default function Notifications(): JSX.Element {
</IconButton>
</Badge>

<Popper open={open} anchorEl={anchorEl} placement="right-end" container={mapElem}>
<Popper open={open} anchorEl={anchorEl} placement="right-end" onClose={handleClickAway} container={mapElem}>
<Paper sx={sxClasses.notificationPanel}>
<Typography component="h3" sx={sxClasses.notificationsTitle}>
{t('appbar.notifications')}
Expand Down
32 changes: 27 additions & 5 deletions packages/geoview-core/src/ui/popper/popper.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
/* eslint-disable react-hooks/exhaustive-deps */
import React, { useEffect, useRef } from 'react';
import { Popper as MaterialPopper, PopperProps } from '@mui/material';

interface EnhancedPopperProps extends PopperProps {
onClose?: () => void;

Check warning on line 5 in packages/geoview-core/src/ui/popper/popper.tsx

View workflow job for this annotation

GitHub Actions / Build demo files / build-geoview

propType "onClose" is not required, but has no corresponding defaultProps declaration

Check warning on line 5 in packages/geoview-core/src/ui/popper/popper.tsx

View workflow job for this annotation

GitHub Actions / Build demo files / build-geoview

propType "onClose" is not required, but has no corresponding defaultProps declaration
}

/**
* Create a popover component
*
* @param {PopperProps} props popover properties
* @param {EnhancedPopperProps} props popover properties
* @returns {JSX.Element} returns popover component
*/
export function Popper(props: PopperProps): JSX.Element {
return <MaterialPopper {...props} />;
}
/* eslint-disable-next-line react/function-component-definition */
export const Popper: React.FC<EnhancedPopperProps> = ({ open, onClose, ...restProps }) => {
const popperRef = useRef<HTMLDivElement>(null);

useEffect(() => {
const handleEscapeKey = (event: KeyboardEvent) => {
if (event.key === 'Escape' && open && onClose) {
// Close the Popper when 'Escape' key is pressed
onClose();
}
};

document.addEventListener('keydown', handleEscapeKey);

return () => {
document.removeEventListener('keydown', handleEscapeKey);
};
}, [open, onClose]);

return <MaterialPopper sx={{ zIndex: '2000' }} {...restProps} open={open} ref={popperRef} />;
};
Loading