-
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the menubar accessibility (#465)
* Bring keyboard handling closer in line with WCAG2.1 * Code cleanup * Fix focusing the menubar on event * Make the tests check that the activeElement is a descendant * More work on the tests * Fixed the focus / tab tests * Added missing test for the space activation * Cleanup the example * Switch to the ARIA menubar example interaction pattern * Set the activeIndex in onActivateRequest * Remove old code * Code cleanup * Remove test for scenario that cannot occur * Remember the last focused menu item * Test fix * Fix license header job * Update examples/example-menubar/package.json Co-authored-by: Frédéric Collonval <fcollonval@users.noreply.github.com> * Small rewordings * Small doc changes * Widgets API update Co-authored-by: Frédéric Collonval <fcollonval@users.noreply.github.com>
- Loading branch information
1 parent
750fea2
commit 14c3380
Showing
10 changed files
with
323 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<!-- | ||
~ Copyright (c) Jupyter Development Team. | ||
~ Distributed under the terms of the Modified BSD License. | ||
--> | ||
|
||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"> | ||
<script type="text/javascript" src="build/bundle.example.js"></script> | ||
<title>MenuBar Example</title> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "@lumino/example-menubar", | ||
"version": "0.1.0-alpha.6", | ||
"private": true, | ||
"scripts": { | ||
"build": "tsc && rollup -c", | ||
"clean": "rimraf build" | ||
}, | ||
"dependencies": { | ||
"@lumino/default-theme": "^1.0.0-alpha.6", | ||
"@lumino/messaging": "^2.0.0-alpha.6", | ||
"@lumino/widgets": "^2.0.0-alpha.6" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-node-resolve": "^13.3.0", | ||
"rimraf": "^3.0.2", | ||
"rollup": "^2.77.3", | ||
"rollup-plugin-styles": "^4.0.0", | ||
"typescript": "~4.7.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright (c) Jupyter Development Team. | ||
* Distributed under the terms of the Modified BSD License. | ||
*/ | ||
|
||
import { createRollupConfig } from '../../rollup.examples.config'; | ||
const rollupConfig = createRollupConfig(); | ||
export default rollupConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// Copyright (c) Jupyter Development Team. | ||
// Distributed under the terms of the Modified BSD License. | ||
|
||
import { CommandRegistry } from '@lumino/commands'; | ||
import { Menu, MenuBar, PanelLayout, Widget } from '@lumino/widgets'; | ||
|
||
import '../style/index.css'; | ||
|
||
/** | ||
* Wrapper widget containing the example application. | ||
*/ | ||
class Application extends Widget { | ||
constructor() { | ||
super({ tag: 'main' }); | ||
} | ||
} | ||
|
||
/** | ||
* Skip link to jump to the main content. | ||
*/ | ||
class SkipLink extends Widget { | ||
/** | ||
* Create a HTMLElement that statically links to "#content". | ||
*/ | ||
static createNode(): HTMLElement { | ||
const node = document.createElement('a'); | ||
node.setAttribute('href', '#content'); | ||
node.innerHTML = 'Skip to the main content'; | ||
node.classList.add('lm-example-skip-link'); | ||
return node; | ||
} | ||
|
||
constructor() { | ||
super({ node: SkipLink.createNode() }); | ||
} | ||
} | ||
|
||
/** | ||
* A Widget containing some content to provide context example. | ||
*/ | ||
class Article extends Widget { | ||
/** | ||
* Create the content structure. | ||
*/ | ||
static createNode(): HTMLElement { | ||
const node = document.createElement('div'); | ||
node.setAttribute('id', 'content'); | ||
node.setAttribute('tabindex', '-1'); | ||
const h1 = document.createElement('h1'); | ||
h1.innerHTML = 'MenuBar Example'; | ||
node.appendChild(h1); | ||
const button = document.createElement('button'); | ||
button.innerHTML = 'A button you can tab to out of the menubar'; | ||
node.appendChild(button); | ||
return node; | ||
} | ||
|
||
constructor() { | ||
super({ node: Article.createNode() }); | ||
} | ||
} | ||
|
||
/** | ||
* Helper Function to add menu items. | ||
*/ | ||
function addMenuItem( | ||
commands: CommandRegistry, | ||
menu: Menu, | ||
command: string, | ||
label: string, | ||
log: string | ||
): void { | ||
commands.addCommand(command, { | ||
label: label, | ||
execute: () => { | ||
console.log(log); | ||
} | ||
}); | ||
menu.addItem({ | ||
type: 'command', | ||
command: command | ||
}); | ||
} | ||
|
||
/** | ||
* Create the MenuBar example application. | ||
*/ | ||
function main(): void { | ||
const app = new Application(); | ||
const appLayout = new PanelLayout(); | ||
app.layout = appLayout; | ||
|
||
const skipLink = new SkipLink(); | ||
|
||
const menubar = new MenuBar(); | ||
const commands = new CommandRegistry(); | ||
|
||
const fileMenu = new Menu({ commands: commands }); | ||
fileMenu.title.label = 'File'; | ||
addMenuItem(commands, fileMenu, 'new', 'New', 'File > New'); | ||
addMenuItem(commands, fileMenu, 'open', 'Open', 'File > Open'); | ||
addMenuItem(commands, fileMenu, 'save', 'Save', 'File > Save'); | ||
menubar.addMenu(fileMenu); | ||
|
||
const editMenu = new Menu({ commands: commands }); | ||
editMenu.title.label = 'Edit'; | ||
addMenuItem(commands, editMenu, 'cut', 'Cut', 'Edit > Cut'); | ||
addMenuItem(commands, editMenu, 'copy', 'Copy', 'Edit > Copy'); | ||
addMenuItem(commands, editMenu, 'paste', 'Paste', 'Edit > Paste'); | ||
menubar.addMenu(editMenu); | ||
|
||
const article = new Article(); | ||
|
||
appLayout.addWidget(skipLink); | ||
appLayout.addWidget(menubar); | ||
appLayout.addWidget(article); | ||
|
||
Widget.attach(app, document.body); | ||
} | ||
|
||
window.onload = main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
Copyright (c) Jupyter Development Team. | ||
Distributed under the terms of the Modified BSD License. | ||
*/ | ||
|
||
.lm-example-skip-link { | ||
position: absolute; | ||
left: -1000px; | ||
top: -1000px; | ||
} | ||
|
||
.lm-example-skip-link:focus { | ||
position: fixed; | ||
left: 50%; | ||
top: 0; | ||
z-index: 10; | ||
padding: 0.5rem 1rem; | ||
box-shadow: 0 0 5px #000; | ||
border-bottom-left-radius: 0.2rem; | ||
border-bottom-right-radius: 0.2rem; | ||
background: #fff; | ||
} | ||
|
||
textarea { | ||
display: block; | ||
} | ||
|
||
#content { | ||
padding: 0 1rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
Copyright (c) Jupyter Development Team. | ||
Distributed under the terms of the Modified BSD License. | ||
*/ | ||
@import '@lumino/default-theme/style/index.css'; | ||
@import './content.css'; | ||
|
||
body { | ||
display: flex; | ||
flex-direction: column; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
right: 0; | ||
bottom: 0; | ||
margin: 0; | ||
padding: 0; | ||
overflow: hidden; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"declaration": false, | ||
"noImplicitAny": true, | ||
"noEmitOnError": true, | ||
"noUnusedLocals": true, | ||
"strictNullChecks": true, | ||
"sourceMap": true, | ||
"module": "ES6", | ||
"moduleResolution": "node", | ||
"target": "ES2018", | ||
"outDir": "./build", | ||
"lib": ["DOM", "ES2018"], | ||
"types": [] | ||
}, | ||
"include": ["src/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.