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

Display Palette category content using keyboard #1714

Merged
merged 9 commits into from
Feb 28, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class PaletteFlyoutContentCategory extends React.Component {
this.onMouseOver = this.onMouseOver.bind(this);
this.onMouseLeave = this.onMouseLeave.bind(this);
this.categoryClicked = this.categoryClicked.bind(this);
this.categoryKeyPressed = this.categoryKeyPressed.bind(this);
this.setPaletteCategory = this.setPaletteCategory.bind(this);
}

onMouseOver(ev) {
Expand Down Expand Up @@ -93,12 +95,22 @@ class PaletteFlyoutContentCategory extends React.Component {
return content;
}

setPaletteCategory(isOpen) {
if (isOpen) {
this.props.canvasController.closePaletteCategory(this.props.category.id);
} else {
this.props.canvasController.openPaletteCategory(this.props.category.id);
}
}

// Returns the category object for a regular category.
getRenderCategory() {
const titleObj = this.getTitleObj();
const content = this.getContent();
return (
<AccordionItem title={titleObj} open={this.props.category.is_open}>
<AccordionItem title={titleObj} open={this.props.category.is_open}
onKeyDown={this.categoryKeyPressed}
>
{content}
</AccordionItem>
);
Expand All @@ -116,7 +128,7 @@ class PaletteFlyoutContentCategory extends React.Component {
onMouseOver={this.onMouseOver}
onMouseLeave={this.onMouseLeave}
>
<div className="palette-flyout-category-item">
<div className="palette-flyout-category-item" tabIndex={-1}>
{itemImage}
{itemText}
</div></div>
Expand Down Expand Up @@ -196,10 +208,17 @@ class PaletteFlyoutContentCategory extends React.Component {
// a category is opened.
evt.stopPropagation();

if (this.props.category.is_open) {
this.props.canvasController.closePaletteCategory(this.props.category.id);
} else {
this.props.canvasController.openPaletteCategory(this.props.category.id);
this.setPaletteCategory(this.props.category.is_open);
}

categoryKeyPressed(evt) {
if (evt.target.className === "bx--accordion__heading") {
if (evt.code === "Enter" || evt.code === "Space") {
evt.preventDefault();
evt.stopPropagation();

this.setPaletteCategory(this.props.category.is_open);
}
}
}

Expand Down
Loading