-
Notifications
You must be signed in to change notification settings - Fork 7
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
WAITP-1211: Entity Dropdown Menu #4672
Changes from 1 commit
158411e
46fde3c
128876e
d4f82d6
e9cd3ac
b7d75ed
a6b4133
566bdb0
6f49d13
01cae45
b41438a
66f633a
e66ba1d
256213c
8d004be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,19 +41,18 @@ const MenuLink = styled(Button).attrs({ | |
`; | ||
|
||
type EntityWithChildren = Entity & { children?: Entity[] }; | ||
|
||
interface EntityMenuProps { | ||
projectCode: string; | ||
children: EntityWithChildren[]; | ||
isLoading: boolean; | ||
} | ||
|
||
/* | ||
* ExpandedList is a recursive component that renders a list of entities and their children to | ||
* display an expandable entity menu. | ||
*/ | ||
export const EntityMenu = ({ | ||
projectCode, | ||
children, | ||
isLoading, | ||
}: { | ||
projectCode: string; | ||
children: EntityWithChildren[]; | ||
isLoading: boolean; | ||
}) => { | ||
export const EntityMenu = ({ projectCode, children, isLoading }: EntityMenuProps) => { | ||
const entityList = children.sort((a, b) => a.name.localeCompare(b.name)); | ||
return ( | ||
<List> | ||
|
@@ -82,7 +81,7 @@ const EntityMenuItem = ({ | |
const [isExpanded, setIsExpanded] = useState(false); | ||
const { data, isLoading } = useEntities(projectCode!, entity.code!, { enabled: isExpanded }); | ||
|
||
const onExpand = () => { | ||
const toggleExpanded = () => { | ||
setIsExpanded(!isExpanded); | ||
}; | ||
|
||
|
@@ -100,12 +99,21 @@ const EntityMenuItem = ({ | |
<MenuLink to={link}> | ||
{entity.name} {entity.type === 'facility' && <HospitalIcon />} | ||
</MenuLink> | ||
<IconButton onClick={onExpand} disabled={parentIsLoading || !nextChildren}> | ||
<IconButton | ||
onClick={toggleExpanded} | ||
disabled={parentIsLoading || !nextChildren} | ||
aria-controls="entity-expand-button" | ||
> | ||
<ExpandIcon /> | ||
</IconButton> | ||
</FlexRow> | ||
{isExpanded && ( | ||
<EntityMenu children={nextChildren} projectCode={projectCode} isLoading={isLoading} /> | ||
<EntityMenu | ||
children={nextChildren} | ||
projectCode={projectCode} | ||
isLoading={isLoading} | ||
aria-expanded={isExpanded} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just checking - does this get carried down to the menu element? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah very good point. I have moved it to the List element and it's always true there since the menu list only shows when expanded. |
||
/> | ||
)} | ||
</div> | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thank you! Can we just add an
aria-label
of something liketoggle menu for ....
?