Skip to content

Commit c3374e4

Browse files
authored
Merge branch 'main' into fix/tools/dev-server-config
2 parents fbf9b14 + 2c2fde1 commit c3374e4

File tree

9 files changed

+42
-37
lines changed

9 files changed

+42
-37
lines changed

.changeset/base-tab-id.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@patternfly/elements": patch
3+
---
4+
`<pf-tabs>`: improved accessibility for elements extending `BaseTab` and
5+
`BaseTabPanel` by assigning random IDs when no exists.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@patternfly/elements": patch
3+
---
4+
5+
`BaseTab`:
6+
- fixed Safari focus issue on keyboard navigation
7+
- fixed Safari focus issue on mouse click

.changeset/two-pugs-add.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@patternfly/pfe-core": patch
3+
---
4+
5+
`overflow-controller`:
6+
- improves display calculations for overflow scroll buttons
7+
- adds smooth scroll behavior

core/pfe-core/controllers/overflow-controller.ts

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ export class OverflowController implements ReactiveController {
4242
}
4343
this.overflowLeft = !this.#hideOverflowButtons && !isElementInView(this.#container, this.firstItem);
4444
this.overflowRight = !this.#hideOverflowButtons && !isElementInView(this.#container, this.lastItem);
45-
this.showScrollButtons = !this.#hideOverflowButtons && (this.overflowLeft || this.overflowRight);
45+
let scrollButtonsWidth = 0;
46+
if (this.overflowLeft || this.overflowRight) {
47+
scrollButtonsWidth = (this.#container.parentElement?.querySelector('button')?.getBoundingClientRect().width || 0) * 2;
48+
}
49+
this.showScrollButtons = !this.#hideOverflowButtons &&
50+
this.#container.scrollWidth > (this.#container.clientWidth + scrollButtonsWidth);
4651
this.host.requestUpdate();
4752
}
4853

@@ -61,35 +66,17 @@ export class OverflowController implements ReactiveController {
6166
if (!this.#container) {
6267
return;
6368
}
64-
let firstElementInView: HTMLElement | undefined;
65-
let lastElementOutOfView: HTMLElement | undefined;
66-
for (let i = 0; i < this.#items.length && !firstElementInView; i++) {
67-
if (isElementInView(this.#container, this.#items[i] as HTMLElement, false)) {
68-
firstElementInView = this.#items[i];
69-
lastElementOutOfView = this.#items[i - 1];
70-
}
71-
}
72-
if (lastElementOutOfView) {
73-
this.#container.scrollLeft -= lastElementOutOfView.scrollWidth;
74-
}
69+
const leftScroll = this.#container.scrollLeft - this.#container.clientWidth;
70+
this.#container.scroll({ left: leftScroll, behavior: 'smooth' });
7571
this.#setOverflowState();
7672
}
7773

7874
scrollRight() {
7975
if (!this.#container) {
8076
return;
8177
}
82-
let lastElementInView: HTMLElement | undefined;
83-
let firstElementOutOfView: HTMLElement | undefined;
84-
for (let i = this.#items.length - 1; i >= 0 && !lastElementInView; i--) {
85-
if (isElementInView(this.#container, this.#items[i] as HTMLElement, false)) {
86-
lastElementInView = this.#items[i];
87-
firstElementOutOfView = this.#items[i + 1];
88-
}
89-
}
90-
if (firstElementOutOfView) {
91-
this.#container.scrollLeft += firstElementOutOfView.scrollWidth;
92-
}
78+
const leftScroll = this.#container.scrollLeft + this.#container.clientWidth;
79+
this.#container.scroll({ left: leftScroll, behavior: 'smooth' });
9380
this.#setOverflowState();
9481
}
9582

elements/pf-tabs/BaseTab.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { LitElement, html } from 'lit';
44
import { queryAssignedElements } from 'lit/decorators/query-assigned-elements.js';
55
import { query } from 'lit/decorators/query.js';
66

7+
import { getRandomId } from '@patternfly/pfe-core/functions/random.js';
78
import { ComposedEvent } from '@patternfly/pfe-core';
89

910
import style from './BaseTab.css';
@@ -37,6 +38,7 @@ export abstract class BaseTab extends LitElement {
3738

3839
connectedCallback() {
3940
super.connectedCallback();
41+
this.id ||= getRandomId(this.localName);
4042
this.addEventListener('click', this.#clickHandler);
4143
this.#internals.role = 'tab';
4244
}
@@ -63,9 +65,14 @@ export abstract class BaseTab extends LitElement {
6365
}
6466
}
6567

68+
focus() {
69+
this.button.focus();
70+
}
71+
6672
#clickHandler() {
6773
if (!this.disabled && this.#internals.ariaDisabled !== 'true' && this.ariaDisabled !== 'true') {
6874
this.active = true;
75+
this.focus(); // safari fix
6976
}
7077
}
7178

elements/pf-tabs/BaseTabPanel.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { LitElement, html } from 'lit';
22

33
import style from './BaseTabPanel.css';
44

5+
import { getRandomId } from '@patternfly/pfe-core/functions/random.js';
6+
57
export abstract class BaseTabPanel extends LitElement {
68
static readonly styles = [style];
79

@@ -17,6 +19,7 @@ export abstract class BaseTabPanel extends LitElement {
1719

1820
connectedCallback() {
1921
super.connectedCallback();
22+
this.id ||= getRandomId('pf-tab-panel');
2023
this.#internals.role = 'tabpanel';
2124
/*
2225
To make it easy for screen reader users to navigate from a tab

elements/pf-tabs/BaseTabs.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,10 @@ export abstract class BaseTabs extends LitElement {
226226
}
227227

228228
if (event.active) {
229+
if (event.tab !== this.#tabindex.activeItem) {
230+
this.#tabindex.updateActiveItem(event.tab);
231+
}
229232
this.activeIndex = this.#allTabs.findIndex(tab => tab === event.tab);
230-
this.#tabindex.updateActiveItem(this.#activeTab);
231233
}
232234
};
233235

elements/pf-tabs/pf-tab-panel.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { customElement } from 'lit/decorators/custom-element.js';
22

3-
import { getRandomId } from '@patternfly/pfe-core/functions/random.js';
4-
53
import styles from './pf-tab-panel.css';
64

75
import { BaseTabPanel } from './BaseTabPanel.js';
@@ -16,11 +14,6 @@ import { BaseTabPanel } from './BaseTabPanel.js';
1614
@customElement('pf-tab-panel')
1715
export class PfTabPanel extends BaseTabPanel {
1816
static readonly styles = [...BaseTabPanel.styles, styles];
19-
20-
connectedCallback() {
21-
super.connectedCallback();
22-
this.id ||= getRandomId('pf-tab-panel');
23-
}
2417
}
2518

2619
declare global {

elements/pf-tabs/pf-tab.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { customElement } from 'lit/decorators/custom-element.js';
22
import { property } from 'lit/decorators/property.js';
33

44
import { observed } from '@patternfly/pfe-core/decorators.js';
5-
import { getRandomId } from '@patternfly/pfe-core/functions/random.js';
65

76
import { BaseTab } from './BaseTab.js';
87

@@ -77,11 +76,6 @@ export class PfTab extends BaseTab {
7776

7877
@observed
7978
@property({ reflect: true, type: Boolean }) disabled = false;
80-
81-
connectedCallback() {
82-
super.connectedCallback();
83-
this.id ||= getRandomId('pf-tab');
84-
}
8579
}
8680

8781
declare global {

0 commit comments

Comments
 (0)