Skip to content

Commit 5bee501

Browse files
committed
bug fixes
1 parent 332c5f9 commit 5bee501

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

src/pg/menu/menu.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,30 +33,34 @@ export default class PgMenu extends HTMLElement {
3333
});
3434
$item.addEventListener('up', (e: any) => {
3535
const { index } = e.detail;
36-
let first = this.items[0].disabled ? 1 : 0;
37-
if (index === first) {
38-
this.focus(this.items.length - 1);
39-
} else {
40-
this.focus(index - 1);
41-
}
36+
this.#focus(index - 1, -1, index);
4237
});
4338
$item.addEventListener('down', (e: any) => {
4439
const { index } = e.detail;
45-
if (index === this.items.length - 1) {
46-
let first = this.items[0].disabled ? 1 : 0;
47-
this.focus(first);
48-
} else {
49-
this.focus(index + 1);
50-
}
40+
this.#focus(index + 1, 1, index);
5141
});
5242
}
5343
});
5444
}
5545

56-
focus(index) {
46+
#focus(index, fallback, initIndex) {
47+
if (index === initIndex) {
48+
return;
49+
}
5750
if (index === -1) {
58-
index = this.items[0].disabled ? 1 : 0;
51+
return this.#focus(this.items.length - 1, fallback, initIndex);
52+
}
53+
if (index >= this.items.length) {
54+
return this.#focus(0, fallback, initIndex);
55+
}
56+
const item = this.$items.children[index] as any;
57+
if (item.focusable === false || this.items[index].disabled) {
58+
return this.#focus(index + fallback, fallback, initIndex);
5959
}
60+
item?.focus();
61+
}
62+
63+
focus(index) {
6064
const item = this.$items.children[index] as HTMLElement;
6165
item?.focus();
6266
}

src/pg/menuDivider/menuDivider.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ import { Component, Prop } from '@pictogrammers/element';
33
import template from './menuDivider.html';
44
import style from './menuDivider.css';
55

6-
const noIcon = 'M0 0h24v24H0V0zm2 2v20h20V2H2z';
7-
86
@Component({
97
selector: 'pg-menu-divider',
108
style,
119
template
1210
})
1311
export default class PgMenuDivider extends HTMLElement {
14-
@Prop() presentational: boolean = false;
12+
@Prop() focusable = false;
1513
}

src/pg/menuItem/menuItem.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const noIcon = 'M0 0h24v24H0V0zm2 2v20h20V2H2z';
1111
template
1212
})
1313
export default class PgMenuItem extends HTMLElement {
14+
static delegatesFocus = true;
15+
1416
@Prop() index: number;
1517
@Prop() label: string = '';
1618
@Prop() checked: boolean = false;

0 commit comments

Comments
 (0)