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(core): make shadow interaction components are recognized as focusable #620

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 7 additions & 2 deletions core/src/components/cat-avatar/cat-avatar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, h, Prop, State, Watch } from '@stencil/core';
import { Component, Element, h, Prop, State, Watch } from '@stencil/core';
import loadImg from '../../utils/load-img';

/**
Expand All @@ -7,11 +7,15 @@ import loadImg from '../../utils/load-img';
@Component({
tag: 'cat-avatar',
styleUrl: 'cat-avatar.scss',
shadow: true
shadow: {
delegatesFocus: true
}
})
export class CatAvatar {
@State() backgroundImage?: string;

@Element() hostElement!: HTMLElement;

/**
* The size of the avatar.
*/
Expand Down Expand Up @@ -70,6 +74,7 @@ export class CatAvatar {

render() {
if (this.url) {
this.hostElement.tabIndex = Number(this.hostElement.getAttribute('tabindex')) || 0;
return (
<a href={this.url} target={this.urlTarget} style={this.cssStyle} class={this.cssClass} aria-label={this.label}>
{this.content}
Expand Down
5 changes: 4 additions & 1 deletion core/src/components/cat-button/cat-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import { findClosest } from '../../utils/find-closest';
@Component({
tag: 'cat-button',
styleUrl: 'cat-button.scss',
shadow: true
shadow: {
delegatesFocus: true
}
})
export class CatButton {
private button!: HTMLButtonElement | HTMLAnchorElement;
Expand Down Expand Up @@ -236,6 +238,7 @@ export class CatButton {
}

render() {
this.hostElement.tabIndex = Number(this.hostElement.getAttribute('tabindex')) || 0;
if (this.url) {
return (
<Host data-button-group={this.buttonGroupPosition}>
Expand Down
2 changes: 1 addition & 1 deletion core/src/components/cat-checkbox/cat-checkbox.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('cat-checkbox', () => {
html: `<cat-checkbox label="Label"></cat-checkbox>`
});
expect(page.root).toEqualLightHtml(`
<cat-checkbox label="Label"></cat-checkbox>
<cat-checkbox label="Label" tabindex="0"></cat-checkbox>
`);
});
});
5 changes: 4 additions & 1 deletion core/src/components/cat-checkbox/cat-checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ let nextUniqueId = 0;
@Component({
tag: 'cat-checkbox',
styleUrls: ['cat-checkbox.scss'],
shadow: true
shadow: {
delegatesFocus: true
}
})
export class CatCheckbox {
private readonly _id = `cat-checkbox-${nextUniqueId++}`;
Expand Down Expand Up @@ -162,6 +164,7 @@ export class CatCheckbox {
}

render() {
this.hostElement.tabIndex = Number(this.hostElement.getAttribute('tabindex')) || 0;
return (
<Host>
<label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('cat-date-inline', () => {
html: `<cat-date-inline></cat-date-inline>`
});
expect(page.root).toEqualLightHtml(`
<cat-date-inline></cat-date-inline>
<cat-date-inline tabindex="0"></cat-date-inline>
`);
});
});
5 changes: 4 additions & 1 deletion core/src/components/cat-date-inline/cat-date-inline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ let nextUniqueId = 0;
@Component({
tag: 'cat-date-inline',
styleUrl: 'cat-date-inline.scss',
shadow: true
shadow: {
delegatesFocus: true
}
})
export class CatDateInline {
private readonly _id = `cat-date-inline-${nextUniqueId++}`;
Expand Down Expand Up @@ -234,6 +236,7 @@ export class CatDateInline {
}

render() {
this.hostElement.tabIndex = Number(this.hostElement.getAttribute('tabindex')) || 0;
const [minDate, maxDate] = this.getMinMaxDate();
const dateGrid = this.dateGrid(this.viewDate.getFullYear(), this.viewDate.getMonth());
const [dateStart, dateEnd] = this.getValue();
Expand Down
2 changes: 1 addition & 1 deletion core/src/components/cat-date/cat-date.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('cat-date', () => {
html: `<cat-date></cat-date>`
});
expect(page.root).toEqualLightHtml(`
<cat-date></cat-date>
<cat-date tabindex="0"></cat-date>
`);
});
});
5 changes: 4 additions & 1 deletion core/src/components/cat-date/cat-date.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import { catI18nRegistry as i18n } from '../cat-i18n/cat-i18n-registry';
@Component({
tag: 'cat-date',
styleUrl: 'cat-date.scss',
shadow: true
shadow: {
delegatesFocus: true
}
})
export class CatDate {
private readonly language = i18n.getLocale();
Expand Down Expand Up @@ -230,6 +232,7 @@ export class CatDate {
}

render() {
this.hostElement.tabIndex = Number(this.hostElement.getAttribute('tabindex')) || 0;
return (
<Host>
<cat-input
Expand Down
2 changes: 1 addition & 1 deletion core/src/components/cat-input/cat-input.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('cat-input', () => {
html: `<cat-input label="Label"></cat-input>`
});
expect(page.root).toEqualLightHtml(`
<cat-input label="Label"></cat-input>
<cat-input label="Label" tabindex="0"></cat-input>
`);
});
});
5 changes: 4 additions & 1 deletion core/src/components/cat-input/cat-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ let nextUniqueId = 0;
@Component({
tag: 'cat-input',
styleUrl: 'cat-input.scss',
shadow: true
shadow: {
delegatesFocus: true
}
})
export class CatInput {
private readonly _id = `cat-input-${nextUniqueId++}`;
Expand Down Expand Up @@ -279,6 +281,7 @@ export class CatInput {
}

render() {
this.hostElement.tabIndex = Number(this.hostElement.getAttribute('tabindex')) || 0;
return (
<div
class={{
Expand Down
2 changes: 1 addition & 1 deletion core/src/components/cat-pagination/cat-pagination.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('cat-pagination', () => {
html: `<cat-pagination></cat-pagination>`
});
expect(page.root).toEqualLightHtml(`
<cat-pagination></cat-pagination>
<cat-pagination tabindex="0"></cat-pagination>
`);
});
});
8 changes: 6 additions & 2 deletions core/src/components/cat-pagination/cat-pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Event, EventEmitter, h, Prop } from '@stencil/core';
import { Component, Element, Event, EventEmitter, h, Prop } from '@stencil/core';
import { catI18nRegistry as i18n } from '../cat-i18n/cat-i18n-registry';

/**
Expand All @@ -11,9 +11,12 @@ import { catI18nRegistry as i18n } from '../cat-i18n/cat-i18n-registry';
@Component({
tag: 'cat-pagination',
styleUrl: 'cat-pagination.scss',
shadow: true
shadow: {
delegatesFocus: true
}
})
export class CatPagination {
@Element() hostElement!: HTMLElement;
/**
* The current page.
*/
Expand Down Expand Up @@ -70,6 +73,7 @@ export class CatPagination {
@Event() catChange!: EventEmitter<number>;

render() {
this.hostElement.tabIndex = Number(this.hostElement.getAttribute('tabindex')) || 0;
return (
<nav role="navigation">
<ol
Expand Down
2 changes: 1 addition & 1 deletion core/src/components/cat-radio/cat-radio.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('cat-radio', () => {
html: `<cat-radio label="Label"></cat-radio>`
});
expect(page.root).toEqualLightHtml(`
<cat-radio label="Label"></cat-radio>
<cat-radio label="Label" tabindex="0"></cat-radio>
`);
});
});
5 changes: 4 additions & 1 deletion core/src/components/cat-radio/cat-radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ let nextUniqueId = 0;
@Component({
tag: 'cat-radio',
styleUrl: 'cat-radio.scss',
shadow: true
shadow: {
delegatesFocus: true
}
})
export class CatRadio {
private readonly _id = `cat-radio-${++nextUniqueId}`;
Expand Down Expand Up @@ -134,6 +136,7 @@ export class CatRadio {
}

render() {
this.hostElement.tabIndex = Number(this.hostElement.getAttribute('tabindex')) || 0;
return (
<Host>
<label
Expand Down
2 changes: 1 addition & 1 deletion core/src/components/cat-select/cat-select.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('cat-select', () => {
html: `<cat-select label="Label"></cat-select>`
});
expect(page.root).toEqualLightHtml(`
<cat-select label="Label"></cat-select>
<cat-select label="Label" tabindex="0"></cat-select>
`);
});
});
5 changes: 4 additions & 1 deletion core/src/components/cat-select/cat-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ let nextTagUniqueId = 0;
@Component({
tag: 'cat-select',
styleUrl: 'cat-select.scss',
shadow: true
shadow: {
delegatesFocus: true
}
})
export class CatSelect {
private static readonly SKELETON_COUNT = 4;
Expand Down Expand Up @@ -576,6 +578,7 @@ export class CatSelect {
}

render() {
this.hostElement.tabIndex = Number(this.hostElement.getAttribute('tabindex')) || 0;
return (
<Host>
<div
Expand Down
2 changes: 1 addition & 1 deletion core/src/components/cat-tabs/cat-tabs.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('cat-tabs', () => {
html: `<cat-tabs></cat-tabs>`
});
expect(page.root).toEqualLightHtml(`
<cat-tabs></cat-tabs>
<cat-tabs tabindex="0"></cat-tabs>
`);
});
});
5 changes: 4 additions & 1 deletion core/src/components/cat-tabs/cat-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { Component, Element, Event, EventEmitter, Host, Listen, Method, Prop, St
@Component({
tag: 'cat-tabs',
styleUrl: 'cat-tabs.scss',
shadow: true
shadow: {
delegatesFocus: true
}
})
export class CatTabs {
private mutationObserver?: MutationObserver;
Expand Down Expand Up @@ -93,6 +95,7 @@ export class CatTabs {
@Event() catChange!: EventEmitter<{ id: string; index: number }>;

render() {
this.hostElement.tabIndex = Number(this.hostElement.getAttribute('tabindex')) || 0;
return (
<Host>
{this.tabs.map((tab: HTMLCatTabElement) => {
Expand Down
2 changes: 1 addition & 1 deletion core/src/components/cat-tag/cat-tag.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('cat-tag', () => {
html: `<cat-tag></cat-tag>`
});
expect(page.root).toEqualHtml(`
<cat-tag>
<cat-tag tabindex="0">
<mock:shadow-root>
<div class="label-container"></div>
<div class="input-wrapper">
Expand Down
5 changes: 4 additions & 1 deletion core/src/components/cat-tag/cat-tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ let nextUniqueId = 0;
@Component({
tag: 'cat-tag',
styleUrl: 'cat-tag.scss',
shadow: true
shadow: {
delegatesFocus: true
}
})
export class CatTag {
private readonly _id = `cat-input-${nextUniqueId++}`;
Expand Down Expand Up @@ -180,6 +182,7 @@ export class CatTag {
}

render() {
this.hostElement.tabIndex = Number(this.hostElement.getAttribute('tabindex')) || 0;
return (
<Host>
<div class={{ 'label-container': true, hidden: this.labelHidden }}>
Expand Down
2 changes: 1 addition & 1 deletion core/src/components/cat-textarea/cat-textarea.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('cat-textarea', () => {
html: `<cat-textarea label="Label"></cat-textarea>`
});
expect(page.root).toEqualLightHtml(`
<cat-textarea label="Label"></cat-textarea>
<cat-textarea label="Label" tabindex="0"></cat-textarea>
`);
});
});
5 changes: 4 additions & 1 deletion core/src/components/cat-textarea/cat-textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ let nextUniqueId = 0;
@Component({
tag: 'cat-textarea',
styleUrl: 'cat-textarea.scss',
shadow: true
shadow: {
delegatesFocus: true
}
})
export class CatTextarea {
private readonly _id = `cat-textarea-${nextUniqueId++}`;
Expand Down Expand Up @@ -208,6 +210,7 @@ export class CatTextarea {
}

render() {
this.hostElement.tabIndex = Number(this.hostElement.getAttribute('tabindex')) || 0;
return (
<Host>
<div
Expand Down
2 changes: 1 addition & 1 deletion core/src/components/cat-time/cat-time.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('cat-time', () => {
html: `<cat-time></cat-time>`
});
expect(page.root).toEqualLightHtml(`
<cat-time></cat-time>
<cat-time tabindex="0"></cat-time>
`);
});
});
5 changes: 4 additions & 1 deletion core/src/components/cat-time/cat-time.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import { clampTime, isAfter, isBefore } from './cat-time-math';
@Component({
tag: 'cat-time',
styleUrl: 'cat-time.scss',
shadow: true
shadow: {
delegatesFocus: true
}
})
export class CatTime {
private readonly language = i18n.getLocale();
Expand Down Expand Up @@ -294,6 +296,7 @@ export class CatTime {
}

render() {
this.hostElement.tabIndex = Number(this.hostElement.getAttribute('tabindex')) || 0;
return (
<Host>
<cat-input
Expand Down
2 changes: 1 addition & 1 deletion core/src/components/cat-toggle/cat-toggle.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('cat-toggle', () => {
html: `<cat-toggle label="Label"></cat-toggle>`
});
expect(page.root).toEqualLightHtml(`
<cat-toggle label="Label"></cat-toggle>
<cat-toggle label="Label" tabindex="0"></cat-toggle>
`);
});
});
5 changes: 4 additions & 1 deletion core/src/components/cat-toggle/cat-toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ let nextUniqueId = 0;
@Component({
tag: 'cat-toggle',
styleUrls: ['cat-toggle.scss'],
shadow: true
shadow: {
delegatesFocus: true
}
})
export class CatToggle {
private readonly _id = `cat-toggle-${nextUniqueId++}`;
Expand Down Expand Up @@ -151,6 +153,7 @@ export class CatToggle {
}

render() {
this.hostElement.tabIndex = Number(this.hostElement.getAttribute('tabindex')) || 0;
return (
<Host>
<label
Expand Down
Loading