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

feat(tabs): implement tabs controller #2577

Merged
merged 52 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
e2f6d78
feat(tabs): implement tabs controller
zeroedin Aug 8, 2023
db2d653
Merge branch 'main' into feat/tabs-controller
zeroedin Aug 11, 2023
e668dc9
fix(tabs): remove BaseTab from test
zeroedin Aug 11, 2023
e3479ac
fix(tabs): correct disabled test to check child button
zeroedin Aug 11, 2023
e0397ea
fix(tabs): dispatch event when active property changes on tab
zeroedin Aug 11, 2023
1833746
fix(tabs): dispatch event only when changing from false to true
zeroedin Aug 11, 2023
285a6d6
fix(tabs): add dynamic tab demo
zeroedin Aug 11, 2023
2b50ad8
fix(tabs): update RTI if tab is disabled
zeroedin Aug 11, 2023
aff35d4
refactor(tabs): mutation observer
zeroedin Aug 14, 2023
2917703
fix(tabs): demo js link
zeroedin Aug 14, 2023
5e631bc
fix(tabs): add TabsController to exports remove Base classes
zeroedin Aug 14, 2023
e2e2e7e
fix(tabs): update active tab onTabExpand
zeroedin Aug 14, 2023
61a7293
fix(core): update overflow when childList updates
zeroedin Aug 14, 2023
520615c
fix(tabs): reduce mutation observer scope
zeroedin Aug 16, 2023
28de8f4
fix(tabs): add missing activeIndex getter
zeroedin Aug 16, 2023
5b39568
fix(tabs): fix bug with tab button before styles on box variant
zeroedin Aug 25, 2023
77afd01
chore(tabs): remove whitespace
zeroedin Aug 25, 2023
2f2cb7f
Merge branch 'main' into feat/tabs-controller
zeroedin Aug 25, 2023
4d94366
fix(core): undo uneeded change to RTI controller
zeroedin Aug 25, 2023
136f35c
chore(tabs): add changeset
zeroedin Aug 25, 2023
3dc5435
chore(core): add changeset
zeroedin Aug 25, 2023
e2e9932
fix(tabs): remove base styles files
zeroedin Aug 28, 2023
da5668f
docs(tabs): add additional documentation
zeroedin Aug 28, 2023
60b1dbd
chore(tabs): update changeset
zeroedin Aug 28, 2023
55c86cd
docs(tabs): add set activeIndex jsDoc
zeroedin Aug 28, 2023
27a9f1b
fix(tabs): refactor mutations callback
zeroedin Aug 28, 2023
3177563
fix(tabs): add override keyword
zeroedin Aug 28, 2023
41effcd
fix(tabs): add override keyword to panel
zeroedin Aug 28, 2023
ade20e8
test(tabs): improve disabled tab testing
zeroedin Aug 28, 2023
3cfa29c
refactor(tabs): check event instanceof type in static method
zeroedin Aug 29, 2023
a6d4f1f
docs(tabs): add active state to nested demo
zeroedin Aug 29, 2023
c639bfa
refactor(tabs): making validation methods required
zeroedin Aug 31, 2023
340bb6d
fix(tabs): additional public api
zeroedin Sep 1, 2023
5feae1c
test(tabs): refactor tab tests using nested describes
zeroedin Nov 1, 2023
bab352a
feat(core): add tabs-controller
zeroedin Nov 1, 2023
265e088
fix(tabs): relink tabs controller from core
zeroedin Nov 1, 2023
a715617
fix(tabs): remove TabsController
zeroedin Nov 1, 2023
c0d9cc9
chore(tabs): update changeset
zeroedin Nov 1, 2023
6dc31e0
chore(core): update changeset
zeroedin Nov 1, 2023
e86af53
fix(tabs): remove TabsController from element package exports
zeroedin Nov 1, 2023
702bbb1
fix(core): add tabs-controller to package exports
zeroedin Nov 1, 2023
b2772de
chore(tabs): update changeset
zeroedin Nov 15, 2023
41555ab
fix(tabs): revert removal of base classes
zeroedin Nov 16, 2023
6e454a7
fix(tabs): re-add isExpandEvent
zeroedin Nov 16, 2023
85ed81d
chore(tabs): add changeset
zeroedin Nov 16, 2023
2a9c26f
docs: update changesets
bennypowers Dec 4, 2023
108c23e
feat(core): loosen logger host type
bennypowers Dec 4, 2023
0fce886
docs: changeset
bennypowers Dec 4, 2023
9d7c877
docs(tabs): split up demos
bennypowers Dec 4, 2023
eae3f52
fix(tabs): loosen type of host for tabscontroller
bennypowers Dec 4, 2023
ab9cc17
refactor(tabs): docs and ordering
bennypowers Dec 4, 2023
8f54b25
chore(tabs): remove commented out code
zeroedin Dec 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions core/pfe-core/controllers/overflow-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,38 @@ import type { ReactiveController, ReactiveControllerHost } from 'lit';
import { isElementInView } from '@patternfly/pfe-core/functions/isElementInView.js';

export interface Options {
/**
* Force hide the scroll buttons regardless of overflow
*/
hideOverflowButtons?: boolean;
/**
* Delay in ms to wait before checking for overflow
*/
scrollTimeoutDelay?: number;
}

export class OverflowController implements ReactiveController {
static #instances = new Set<OverflowController>();

static {
// on resize check for overflows to add or remove scroll buttons
window.addEventListener('resize', () => {
for (const instance of this.#instances) {
instance.onScroll();
}
}, { capture: false });
}

/** Overflow container */
#container?: HTMLElement;
/** Children that can overflow */
#items: HTMLElement[] = [];

#scrollTimeoutDelay = 0;
#scrollTimeoutDelay: number;
#scrollTimeout?: ReturnType<typeof setTimeout>;

/** Default state */
#hideOverflowButtons = false;
#hideOverflowButtons: boolean;
showScrollButtons = false;
overflowLeft = false;
overflowRight = false;
Expand All @@ -31,15 +49,20 @@ export class OverflowController implements ReactiveController {

constructor(public host: ReactiveControllerHost & Element, private options?: Options) {
this.host.addController(this);
if (options?.hideOverflowButtons) {
this.#hideOverflowButtons = options?.hideOverflowButtons;
this.#hideOverflowButtons = options?.hideOverflowButtons ?? false;
this.#scrollTimeoutDelay = options?.scrollTimeoutDelay ?? 0;
if (host.isConnected) {
OverflowController.#instances.add(this);
}
}

#setOverflowState(): void {
if (!this.firstItem || !this.lastItem || !this.#container) {
return;
}
const prevLeft = this.overflowLeft;
const prevRight = this.overflowRight;

this.overflowLeft = !this.#hideOverflowButtons && !isElementInView(this.#container, this.firstItem);
this.overflowRight = !this.#hideOverflowButtons && !isElementInView(this.#container, this.lastItem);
let scrollButtonsWidth = 0;
Expand All @@ -48,7 +71,11 @@ export class OverflowController implements ReactiveController {
}
this.showScrollButtons = !this.#hideOverflowButtons &&
this.#container.scrollWidth > (this.#container.clientWidth + scrollButtonsWidth);
this.host.requestUpdate();

// only request update if there has been a change
if ((prevLeft !== this.overflowLeft) || (prevRight !== this.overflowRight)) {
this.host.requestUpdate();
}
}

init(container: HTMLElement, items: HTMLElement[]) {
Expand Down
10 changes: 6 additions & 4 deletions core/pfe-core/controllers/roving-tabindex-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,15 @@ export class RovingTabindexController<
/**
* from array of HTML items, and sets active items
*/
initItems(items: ItemType[], itemsContainer: HTMLElement = this.host) {
initItems(items: ItemType[], itemsContainer: HTMLElement = this.host, setActiveItem = true) {
this.#items = items ?? [];
const focusableItems = this.#focusableItems;
const [focusableItem] = focusableItems;
this.#activeItem = focusableItem;
for (const item of focusableItems) {
item.tabIndex = this.#activeItem === item ? 0 : -1;
if (setActiveItem) {
this.#activeItem = focusableItem;
for (const item of focusableItems) {
item.tabIndex = this.#activeItem === item ? 0 : -1;
}
}
/**
* removes listener on previous contained and applies it to new container
Expand Down
96 changes: 0 additions & 96 deletions elements/pf-tabs/BaseTab.ts

This file was deleted.

35 changes: 0 additions & 35 deletions elements/pf-tabs/BaseTabPanel.ts

This file was deleted.

Loading