Skip to content

Commit be0c53e

Browse files
committed
bug fixes
1 parent b547f59 commit be0c53e

File tree

8 files changed

+58
-53
lines changed

8 files changed

+58
-53
lines changed

src/pg/menu/README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
The `pg-menu` component renders a menu list. Menus can be used inline, but are usually created by a parent component. For example:
44

5-
- `button-menu` - Button Menu
6-
- `button-icon-menu` - Button Icon Menu
5+
- `pg-button-menu` - Button Menu
6+
- Default item `type` is `PgMenuItem`
7+
- `pg-button-icon-menu` - Button Icon Menu
8+
- Default item `type` is `PgMenuItem`
79
- `PgMenuOverlay` Utility overlay for menus.
10+
- The item `type` is required.
811

912
```typescript
10-
import '@pictogrammers/components/pgMenu.js';
13+
import '@pictogrammers/components/pg/menu';
1114
```
1215

1316
```html
@@ -16,15 +19,19 @@ import '@pictogrammers/components/pgMenu.js';
1619

1720
| Attributes | Tested | Description |
1821
| ---------- | -------- | ----------- |
19-
| `items` | | Set items list. |
22+
| `items` | | Set items list. Ex: `{ type: PgMenuItem }` |
2023

2124
```typescript
25+
import PgMenuItem from '@pictogrammers/components/pg/menuItem';
26+
27+
// ...
2228
@Part() $menu: PgMenu;
2329

2430
connectedCallback() {
2531
this.$menu.items = [{
2632
label: 'Item 1',
27-
value: 'item1'
33+
value: 'item1',
34+
type: PgMenuItem
2835
}];
2936
}
3037
```

src/pg/menu/__examples__/basic/basic.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ export default class XPgMenuBasic extends HTMLElement {
2323
this.$menu.addEventListener('select', this.#handleSelect.bind(this));
2424
}
2525

26+
previousItem: any = null;
2627
#handleSelect(e: any) {
28+
const { item } = e.detail;
29+
if (this.previousItem !== null) {
30+
this.previousItem.checked = false;
31+
}
32+
item.checked = true;
33+
this.previousItem = item;
2734
// update clicked result
2835
this.$result.textContent = JSON.stringify(e.detail);
2936
}

src/pg/menu/menu.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ export default class PgMenu extends HTMLElement {
1717

1818
@Part() $items: HTMLDivElement;
1919

20-
previousIndex = -1;
21-
2220
connectedCallback() {
2321
forEach({
2422
container: this.$items,
@@ -32,11 +30,6 @@ export default class PgMenu extends HTMLElement {
3230
this.dispatchEvent(new CustomEvent('select', {
3331
detail: { index, item }
3432
}));
35-
if (this.previousIndex !== -1) {
36-
(this.$items.children[this.previousIndex] as PgMenuItem).checked = false;
37-
}
38-
$item.checked = true;
39-
this.previousIndex = index;
4033
});
4134
$item.addEventListener('up', (e: any) => {
4235
const { index } = e.detail;
@@ -56,9 +49,6 @@ export default class PgMenu extends HTMLElement {
5649
this.focus(index + 1);
5750
}
5851
});
59-
if (item.checked) {
60-
this.previousIndex = $item.index;
61-
}
6252
}
6353
});
6454
}

src/pg/overlayMenu/README.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
11
# Overlay Menu
22

3-
The `PgOverlayMenu` creates a menu.
3+
The `PgOverlayMenu` creates a menu creates an overlay menu above a source element. For standard menu lists use the `PgMenuItem` for the check.
44

55
```typescript
6-
if (this.#isOpen) { return; }
7-
this.#isOpen = true;
8-
const result = await PgOverlayMenu.open({
9-
source: this.$element,
10-
items: [{
11-
label: 'Item 1',
12-
value: 'item1'
13-
}, {
14-
label: 'Item 2',
15-
value: 'item2'
16-
}]
17-
});
18-
console.log(result);
6+
import PgMenuItem from '@pictogrammers/components/pg/menuItem';
7+
8+
#isOpen: false;
9+
handleSourceClick() {
10+
if (this.#isOpen) { return; }
11+
this.#isOpen = true;
12+
const result = await PgOverlayMenu.open({
13+
source: this.$element,
14+
items: [{
15+
label: 'Item 1',
16+
value: 'item1',
17+
type: PgMenuItem
18+
}, {
19+
label: 'Item 2',
20+
value: 'item2',
21+
type: PgMenuItem
22+
}]
23+
});
24+
this.#isOpen = false;
25+
console.log(result);
26+
}
1927
```

src/pg/overlayMenu/__examples__/basic/basic.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Component, Part, Prop } from '@pictogrammers/element';
2+
import PgMenuItem from '../../../menuItem/menuItem';
23
import PgOverlayMenu from '../../overlayMenu';
34

45
import template from './basic.html';
@@ -25,11 +26,13 @@ export default class XPgOverlayMenuBasic extends HTMLElement {
2526
if (this.#menuOpen) { return; }
2627
const items = [{
2728
label: 'Item 1',
28-
value: 'item1'
29+
value: 'item1',
30+
type: PgMenuItem
2931
},
3032
{
3133
label: 'Item 2',
32-
value: 'item2'
34+
value: 'item2',
35+
type: PgMenuItem
3336
}];
3437
this.#menuOpen = true;
3538
const result = await PgOverlayMenu.open({

src/pg/tabs/partials/tab.css

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,13 @@
3030
border-color: var(--pg-tab-border, #453C4F);
3131
}
3232

33-
[part="button"]:active::before {
34-
content: '';
35-
position: absolute;
36-
top: -1px;
37-
right: -1px;
38-
bottom: 0;
39-
left: -1px;
40-
border-radius: 0.25rem 0.25rem 0 0;
41-
box-shadow: 0 0 0 3px var(--pg-focus-color, rgb(79, 143, 249, 0.6));
33+
[part="button"].selected:focus-visible {
34+
color: #197BE0;
35+
border-color: rgb(79, 143, 249);
4236
}
4337

44-
[part="button"]:focus::before {
45-
pointer-events: none;
46-
content: '';
47-
position: absolute;
48-
top: -1px;
49-
right: -1px;
50-
bottom: 0;
51-
left: -1px;
52-
border-radius: 0.25rem 0.25rem 0 0;
53-
box-shadow: 0 0 0 3px var(--pg-focus-color, rgb(79, 143, 249, 0.5));
38+
[part="button"]:not(.selected):focus-visible {
39+
background: var(--pg-focus-color, rgb(79, 143, 249, 0.15));
40+
border-color: rgb(79, 143, 249);
41+
color: #197BE0;
5442
}

src/pg/treeItem/treeItem.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
z-index: 1;
113113
}
114114

115-
[part=item]:hover {
115+
[part=item]:not(.dragging):hover {
116116
background: var(--pg-tree-item-background-hover, rgb(69, 60, 79, 0.1));
117117
}
118118
[part=item].items.selected {
@@ -221,6 +221,7 @@
221221
background: rgba(255, 255, 255, 0.5);
222222
user-select: none;
223223
margin: -0.25rem;
224+
border: 2px dashed rgb(79, 143, 249);
224225
}
225226
[part=items].dragging {
226227
--pg-_is-index-dragging: true;

src/pg/treeItem/treeItem.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { Component, Prop, Part, forEach } from '@pictogrammers/element';
22

3-
import template from './treeItem.html';
4-
import style from './treeItem.css';
53
import PgIcon from '../icon/icon';
64
import PgTreeButtonIcon from '../treeButtonIcon/treeButtonIcon';
75

6+
import template from './treeItem.html';
7+
import style from './treeItem.css';
8+
89
const noIcon = 'M0 0h24v24H0V0zm2 2v20h20V2H2z';
910

1011
@Component({

0 commit comments

Comments
 (0)