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

Close launcher button styling and close launcher with delete key #655

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 33 additions & 6 deletions packages/widgets/src/tabbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,15 +777,28 @@ export class TabBar<T> extends Widget {
return;
}

// Get focus element that is in focus by the tab key
const focusedElement = document.activeElement;
// Check if Delete key has been pressed and Delete that tab
if (event.key === 'Delete') {
krassowski marked this conversation as resolved.
Show resolved Hide resolved
const index = ArrayExt.findFirstIndex(this.contentNode.children, tab =>
tab.contains(focusedElement)
);
if (index >= 0) {
this.currentIndex = index;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this here?

let title = this._titles[index];
event.preventDefault();
event.stopPropagation();
this._tabCloseRequested.emit({ index, title });
return;
}
}
// Check if Enter or Spacebar key has been pressed and open that tab
if (
event.key === 'Enter' ||
event.key === 'Spacebar' ||
event.key === ' '
) {
// Get focus element that is in focus by the tab key
const focusedElement = document.activeElement;

// Test first if the focus is on the add button node
if (
this.addButtonEnabled &&
Expand All @@ -808,6 +821,7 @@ export class TabBar<T> extends Widget {
} else if (ARROW_KEYS.includes(event.key)) {
// Create a list of all focusable elements in the tab bar.
const focusable: Element[] = [...this.contentNode.children];

if (this.addButtonEnabled) {
focusable.push(this.addButtonNode);
}
Expand Down Expand Up @@ -1730,7 +1744,11 @@ export namespace TabBar {
let className = this.createIconClass(data);

// If title.icon is undefined, it will be ignored.
return h.div({ className }, title.icon!, title.iconLabel);
return h.div(
{ className, 'aria-hidden': 'true' },
title.icon!,
title.iconLabel
);
}

/**
Expand All @@ -1741,7 +1759,14 @@ export namespace TabBar {
* @returns A virtual element representing the tab label.
*/
renderLabel(data: IRenderData<any>): VirtualElement {
return h.div({ className: 'lm-TabBar-tabLabel' }, data.title.label);
return h.div(
{
className: 'lm-TabBar-tabLabel',
tabindex: '-1',
'aria-hidden': 'true'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this aria-hidden: true?

},
data.title.label
);
}

/**
Expand All @@ -1752,7 +1777,9 @@ export namespace TabBar {
* @returns A virtual element representing the tab close icon.
*/
renderCloseIcon(data: IRenderData<any>): VirtualElement {
return h.div({ className: 'lm-TabBar-tabCloseIcon' });
return h.div({
className: 'lm-TabBar-tabCloseIcon'
});
}

/**
Expand Down
3 changes: 3 additions & 0 deletions packages/widgets/style/tabbar.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
.lm-TabBar-tabIcon,
.lm-TabBar-tabCloseIcon {
flex: 0 0 auto;
border: none;
background: none;
padding: 0;
}

.lm-TabBar-tabLabel {
Expand Down