mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-23 10:51:30 +00:00
* Fix ally issues for newCollection panel's advanced section * Resolved test snapshot issue * Fix a11y data explorer expand/collapse using keyboard issue
64 lines
1.7 KiB
TypeScript
64 lines
1.7 KiB
TypeScript
import { Icon, Label, Stack } from "@fluentui/react";
|
|
import * as React from "react";
|
|
import { NormalizedEventKey } from "../../../Common/Constants";
|
|
import { accordionStackTokens } from "../Settings/SettingsRenderUtils";
|
|
|
|
export interface CollapsibleSectionProps {
|
|
title: string;
|
|
isExpandedByDefault: boolean;
|
|
onExpand?: () => void;
|
|
}
|
|
|
|
export interface CollapsibleSectionState {
|
|
isExpanded: boolean;
|
|
}
|
|
|
|
export class CollapsibleSectionComponent extends React.Component<CollapsibleSectionProps, CollapsibleSectionState> {
|
|
constructor(props: CollapsibleSectionProps) {
|
|
super(props);
|
|
this.state = {
|
|
isExpanded: this.props.isExpandedByDefault,
|
|
};
|
|
}
|
|
|
|
private toggleCollapsed = (): void => {
|
|
this.setState({ isExpanded: !this.state.isExpanded });
|
|
};
|
|
|
|
public componentDidUpdate(): void {
|
|
if (this.state.isExpanded && this.props.onExpand) {
|
|
this.props.onExpand();
|
|
}
|
|
}
|
|
|
|
private onKeyPress = (event: React.KeyboardEvent) => {
|
|
if (event.key === NormalizedEventKey.Space || event.key === NormalizedEventKey.Enter) {
|
|
this.toggleCollapsed();
|
|
event.stopPropagation();
|
|
}
|
|
};
|
|
|
|
public render(): JSX.Element {
|
|
return (
|
|
<>
|
|
<Stack
|
|
className="collapsibleSection"
|
|
horizontal
|
|
verticalAlign="center"
|
|
tokens={accordionStackTokens}
|
|
onClick={this.toggleCollapsed}
|
|
onKeyPress={this.onKeyPress}
|
|
tabIndex={0}
|
|
aria-name="Advanced"
|
|
role="button"
|
|
aria-expanded={this.state.isExpanded}
|
|
>
|
|
<Icon iconName={this.state.isExpanded ? "ChevronDown" : "ChevronRight"} />
|
|
<Label>{this.props.title}</Label>
|
|
</Stack>
|
|
{this.state.isExpanded && this.props.children}
|
|
</>
|
|
);
|
|
}
|
|
}
|