1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-06-14 01:16:17 +02:00

Fix(1-3553): fix focus styles and tab navigation for segments + constraints (#9655)

Fixes a few small focus styling and tab navigation issues for the new
segments + constraints.

Before:
The segment acc header was tabbable even though you can't do anything
with it (by mouse or by keyboard)

![image](https://github.com/user-attachments/assets/de5c07ee-e55c-45f4-bd6e-3d978a0a51ca)

The focus color would stay even when you're focusing stuff inside the
accordion

![image](https://github.com/user-attachments/assets/1a75038b-256f-43b5-95ed-0a3d455d17f8)

Constraint items have focus styles that exceed the accordion borders,
causing a weird squaring effect:

![image](https://github.com/user-attachments/assets/638c9f5d-daf0-4570-8323-49141183dad8)

After:
The segment acc header isn't reachable by tab anymore.

The segment acc header doesn't change its background color on elements
inside getting focus:

![image](https://github.com/user-attachments/assets/4756e8b0-b461-49df-bf3e-ec8d26142877)

The constraint item has rounded corners for focus styles too:

![image](https://github.com/user-attachments/assets/fccf94e4-8b7a-4823-bcf5-24a0fe046cf7)

![image](https://github.com/user-attachments/assets/90020d85-990c-41de-9acb-ab2cc81a8f66)
This commit is contained in:
Thomas Heartman 2025-04-02 13:37:16 +02:00 committed by GitHub
parent bba85dc9b0
commit 645b005f29
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 19 additions and 11 deletions

View File

@ -112,14 +112,12 @@ export const ConstraintItemHeader: FC<ConstraintItemHeaderProps> = ({
) : null} ) : null}
</StyledOperatorGroup> </StyledOperatorGroup>
<div> <div>
<div> <ValuesList
<ValuesList values={items}
values={items} onSetTruncated={onSetTruncated}
onSetTruncated={onSetTruncated} tooltips={tooltips}
tooltips={tooltips} />
/> {viewMore}
{viewMore}
</div>
</div> </div>
</StyledConstraintContainer> </StyledConstraintContainer>
</StrategyEvaluationItem> </StrategyEvaluationItem>

View File

@ -35,6 +35,7 @@ const StyledAccordion = styled(Accordion)(({ theme }) => ({
'&:before': { '&:before': {
opacity: '0', opacity: '0',
}, },
overflow: 'hidden',
})); }));
const StyledAccordionSummary = styled(AccordionSummary)(({ theme }) => ({ const StyledAccordionSummary = styled(AccordionSummary)(({ theme }) => ({

View File

@ -20,7 +20,7 @@ const StyledHeaderMetaInfo = styled('div')(({ theme }) => ({
}, },
})); }));
const StyledExpandItem = styled('div')(({ theme }) => ({ const StyledExpandItem = styled('p')(({ theme }) => ({
color: theme.palette.secondary.main, color: theme.palette.secondary.main,
margin: theme.spacing(0.25, 0, 0, 0.75), margin: theme.spacing(0.25, 0, 0, 0.75),
fontSize: theme.fontSizes.smallerBody, fontSize: theme.fontSizes.smallerBody,

View File

@ -1,4 +1,4 @@
import { useMemo, useState, type FC } from 'react'; import { useId, useMemo, useState, type FC } from 'react';
import { Link } from 'react-router-dom'; import { Link } from 'react-router-dom';
import type { ISegment } from 'interfaces/segment'; import type { ISegment } from 'interfaces/segment';
import { import {
@ -41,6 +41,9 @@ const StyledAccordion = styled(Accordion)(() => ({
const StyledAccordionSummary = styled(AccordionSummary)(({ theme }) => ({ const StyledAccordionSummary = styled(AccordionSummary)(({ theme }) => ({
fontSize: theme.typography.body2.fontSize, fontSize: theme.typography.body2.fontSize,
minHeight: 'unset', minHeight: 'unset',
':focus-within': {
backgroundColor: 'inherit',
},
})); }));
const StyledAccordionDetails = styled(AccordionDetails)(({ theme }) => ({ const StyledAccordionDetails = styled(AccordionDetails)(({ theme }) => ({
@ -77,6 +80,7 @@ export const SegmentItem: FC<SegmentItemProps> = ({
constraintList, constraintList,
}) => { }) => {
const [isOpen, setIsOpen] = useState(isExpanded || false); const [isOpen, setIsOpen] = useState(isExpanded || false);
const segmentDetailsId = useId();
const constraints = useMemo(() => { const constraints = useMemo(() => {
if (constraintList) { if (constraintList) {
@ -110,7 +114,11 @@ export const SegmentItem: FC<SegmentItemProps> = ({
disableGutters disableGutters
TransitionProps={{ mountOnEnter: true, unmountOnExit: true }} TransitionProps={{ mountOnEnter: true, unmountOnExit: true }}
> >
<StyledAccordionSummary id={`segment-accordion-${segment.id}`}> <StyledAccordionSummary
id={`segment-accordion-${segment.id}`}
tabIndex={-1}
aria-controls={segmentDetailsId}
>
<StrategyEvaluationItem type='Segment'> <StrategyEvaluationItem type='Segment'>
<StyledLink to={`/segments/edit/${segment.id}`}> <StyledLink to={`/segments/edit/${segment.id}`}>
{segment.name} {segment.name}
@ -120,6 +128,7 @@ export const SegmentItem: FC<SegmentItemProps> = ({
{!isExpanded ? ( {!isExpanded ? (
<StyledActionsContainer> <StyledActionsContainer>
<StyledButton <StyledButton
aria-controls={segmentDetailsId}
size='small' size='small'
variant='outlined' variant='outlined'
onClick={() => setIsOpen((value) => !value)} onClick={() => setIsOpen((value) => !value)}