Skip to content
Open
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
18 changes: 12 additions & 6 deletions src/components/elements/list/list-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ const ListItem: FunctionComponent<ListItemModel> = memo(
* @param {string} id - Item identifier
*/
const handleKeyPress = useCallback((ev: KeyboardEvent, id: string) => {
if (ev.key === 'Enter') {
if (ev.key === 'Enter' || ev.key === ' ') {
ev.preventDefault();
handleOnClick(id);
}
}, []);
}, [handleOnClick]);

return (
<ListItemStyle
Expand All @@ -61,7 +62,10 @@ const ListItem: FunctionComponent<ListItemModel> = memo(
$active={active}
tabIndex={0}
$selectable={selectable}
onKeyUp={(ev) => handleKeyPress(ev, id)}
onKeyDown={(ev) => handleKeyPress(ev, id)}
role="listitem"
aria-selected={active}
aria-describedby={description ? `${id}-description` : undefined}
>
{selectable ? (
<CheckboxWrapper>
Expand All @@ -77,9 +81,11 @@ const ListItem: FunctionComponent<ListItemModel> = memo(
) : null}
<StyleAndDescription $selectable={selectable}>
<TitleStyle theme={theme}>{title}</TitleStyle>
<TitleDescriptionStyle theme={theme}>
{description}
</TitleDescriptionStyle>
{description && (
<TitleDescriptionStyle theme={theme} id={`${id}-description`}>
{description}
</TitleDescriptionStyle>
)}
</StyleAndDescription>
</ListItemStyle>
);
Expand Down
65 changes: 44 additions & 21 deletions src/components/elements/list/list.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,40 @@ export const ListItemStyle = styled.li<{
p.$active ? themeStyles.border(p.$theme) : themeStyles.transparent};
flex-direction: ${(p) => (p.$selectable ? 'row' : 'column')};
background: ${(p) => p.$theme.toolbarBtnBgColor};
padding: 0.25rem;
width: calc(100% - 0.5rem);
padding: 0.5rem;
width: calc(100% - 1rem);
user-select: none;
border-radius: 4px;
transition: all 0.15s ease-out;
margin-bottom: 0.625rem;

&:last-child {
margin-bottom: 0;
}

&:hover {
border: ${(p) => themeStyles.border(p.$theme)};
cursor: pointer;
background: ${(p) => p.$theme.buttonHoverBgColor || p.$theme.toolbarBtnBgColor};
}

&:focus-visible {
outline: 2px solid ${(p) => p.$theme.primary || '#0077ff'};
outline-offset: 2px;
}
`;

// Title styles
export const TitleStyle = styled.h1<{ theme: Theme }>`
color: ${(p) => p.theme.iconColor || p.theme.primary};
font-size: 1rem;
font-weight: normal;
margin: 0.2rem 0;
font-size: 0.95rem;
font-weight: 500;
margin: 0 0 0.25rem 0;
text-align: left;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
max-width: 100%;
align-self: flex-start;
`;

Expand All @@ -103,39 +119,46 @@ export const TitleDescriptionStyle = styled.p<{ theme: Theme }>`
font-size: 0.8rem;
font-weight: normal;
margin: 0;
padding: 0.1rem;
padding: 0;
text-align: left;
width: 100%;
color: ${(p) => p.theme.cardSubtitleColor};
line-height: 1.3;
`;

// Checkbox components with improved structure
export const CheckboxWrapper = styled.span`
${flexContainer}
width: 2rem;
width: 1.75rem;
min-width: 1.75rem;
justify-content: center;
align-items: center;
`;

export const CheckboxStyle = styled.span<{ selected?: boolean; theme: Theme }>`
${flexContainer}
justify-content: center;
width: 1.25rem;
height: 1.25rem;
margin: 0 0.25rem 0 0.1rem;
border-radius: 50%;
background: ${(p) => (p.selected ? p.theme.primary : p.theme.toolbarBgColor)};
${(p) => !p.selected && `box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.1)`};
color: #ffffff;

svg {
width: 80%;
height: 80%;
align-items: center;
border: 1px solid ${(p) => p.theme.buttonBorderColor || p.theme.primary};
border-radius: 3px;
height: 18px;
width: 18px;
background: ${(p) => (p.selected ? p.theme.primary : 'transparent')};
color: white;
transition: all 0.15s ease-out;

& svg {
height: 12px;
width: 12px;
display: ${(p) => (p.selected ? 'block' : 'none')};
}
`;

// Content wrapper with conditional width
// Wrapper for title and description in selectable mode
export const StyleAndDescription = styled.div<{ $selectable?: boolean }>`
${flexContainer}
display: flex;
flex-direction: column;
width: ${(p) => (p.$selectable ? 'calc(100% - 2rem)' : '100%')};
width: 100%;
overflow: hidden;
padding-left: ${(p) => (p.$selectable ? '0.5rem' : '0')};
`;
83 changes: 57 additions & 26 deletions src/components/elements/popover/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import React, {
memo,
} from 'react';
import useCloseClickOutside from 'src/components/effects/useCloseClickOutside';
import { useFocusTrap } from 'src/hooks/useFocusTrap';
import { ChevronDown, CloseIcon } from 'src/components/icons';
import { PopOverModel } from './popover.model';
import {
Expand Down Expand Up @@ -52,7 +53,7 @@ const popoverReducer = (state: State, action: Action): State => {
*/
const PopOver: FunctionComponent<PopOverModel> = ({
children,
position,
position = 'bottom', // Default to bottom positioning
placeholder,
theme,
width = 350,
Expand All @@ -61,6 +62,8 @@ const PopOver: FunctionComponent<PopOverModel> = ({
$isMobile = false,
}) => {
const ref = useRef<HTMLDivElement>(null);
const triggerRef = useRef<HTMLDivElement>(null);

const [state, dispatch] = useReducer(popoverReducer, {
open: false,
isVisible: false,
Expand All @@ -73,12 +76,21 @@ const PopOver: FunctionComponent<PopOverModel> = ({
const closePopover = useCallback(() => {
dispatch({ type: 'CLOSE' });
}, []);

const focusTrapRef = useFocusTrap(state.open, closePopover);

const handleKeyPress = useCallback((ev: React.KeyboardEvent) => {
if (ev.key === 'Enter') {
if (ev.key === 'Enter' || ev.key === ' ') {
ev.preventDefault();
dispatch({ type: 'TOGGLE' });
} else if (ev.key === 'Escape' && state.open) {
ev.preventDefault();
dispatch({ type: 'CLOSE' });
} else if (ev.key === 'ArrowDown' && !state.open) {
ev.preventDefault();
dispatch({ type: 'TOGGLE' });
}
}, []);
}, [state.open]);

useCloseClickOutside(ref, closePopover);

Expand All @@ -93,45 +105,64 @@ const PopOver: FunctionComponent<PopOverModel> = ({
}
}, [state.open]);

// Return focus to trigger when popover closes
useEffect(() => {
if (!state.open && triggerRef.current) {
triggerRef.current.focus();
}
}, [state.open]);

return (
<>
<PopoverWrapper ref={ref}>
<Selecter
role="button"
onClick={toggleOpen}
$theme={theme}
$open={state.open}
$isDarkMode={isDarkMode}
tabIndex={0}
onKeyUp={handleKeyPress}
$isMobile={$isMobile}
title={placeholder}
>
<SelecterIcon $theme={theme} $open={state.open}>
{icon || <ChevronDown />}
</SelecterIcon>
{placeholder && !$isMobile ? (
<SelecterLabel>{placeholder}</SelecterLabel>
) : null}
</Selecter>
</PopoverWrapper>
<PopoverWrapper ref={ref}>
<Selecter
role="button"
onClick={toggleOpen}
$theme={theme}
$open={state.open}
$isDarkMode={isDarkMode}
tabIndex={0}
onKeyDown={handleKeyPress}
$isMobile={$isMobile}
title={placeholder}
aria-expanded={state.open}
aria-haspopup="menu"
aria-controls={state.open ? 'popover-content' : undefined}
id="popover-trigger"
ref={triggerRef}
>
<SelecterIcon $theme={theme} $open={state.open}>
{icon || <ChevronDown />}
</SelecterIcon>
{placeholder && !$isMobile ? (
<SelecterLabel>{placeholder}</SelecterLabel>
) : null}
</Selecter>
{state.open ? (
<PopoverHolder
$position={position}
$width={width}
$theme={theme}
$isMobile={$isMobile}
$visible={state.isVisible}
id="popover-content"
role="menu"
aria-labelledby="popover-trigger"
ref={focusTrapRef}
>
<Header>
<CloseButton theme={theme} onClick={closePopover}>
<CloseButton
theme={theme}
onClick={closePopover}
aria-label="Close popover"
title="Close popover"
>
<CloseIcon />
</CloseButton>
</Header>
<MemoizedContent>{children}</MemoizedContent>
</PopoverHolder>
) : null}
</>
</PopoverWrapper>
);
};

Expand Down
Loading