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

refactor: prepare for lit@3.0 usage #3776

Merged
merged 1 commit into from
Dec 1, 2023
Merged
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
2 changes: 1 addition & 1 deletion packages/action-bar/src/ActionBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class ActionBar extends SpectrumElement {
*
* @param {String} variant
*/
@property({ type: String, reflect: true })
@property({ type: String })
public set variant(variant: string) {
if (variant === this.variant) {
return;
Expand Down
4 changes: 4 additions & 0 deletions packages/button/src/Button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ export class Button extends SizedMixin(ButtonBase, { noDefaultSize: true }) {
this.treatment = quiet ? 'outline' : 'fill';
}

public get quiet(): boolean {
return this.treatment === 'outline';
}

protected override firstUpdated(changes: PropertyValues<this>): void {
super.firstUpdated(changes);
// There is no Spectrum design context for an `<sp-button>` without a variant
Expand Down
12 changes: 7 additions & 5 deletions packages/overlay/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ export const runOverlayTriggerTests = (type: string): void => {
expect(await isOnTopLayer(this.hoverContent)).to.be.false;

const rect = this.outerTrigger.getBoundingClientRect();
const close = oneEvent(this.outerTrigger, 'sp-closed');
const open = oneEvent(this.outerTrigger, 'sp-opened');
await sendMouse({
steps: [
{
Expand All @@ -640,10 +640,12 @@ export const runOverlayTriggerTests = (type: string): void => {
},
],
});
await nextFrame();
await nextFrame();
await nextFrame();
await nextFrame();
await open;
const close = oneEvent(this.outerTrigger, 'sp-closed');
expect(
await isOnTopLayer(this.hoverContent),
'hover content is available at point'
).to.be.true;
await sendMouse({
steps: [
{
Expand Down
3 changes: 3 additions & 0 deletions packages/overlay/test/overlay-update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ describe('sp-update-overlays event', () => {
'[label="Other things"]'
) as AccordionItem;

el.content = 'click';
await elementUpdated(el);

const height0 = container.getBoundingClientRect().height;

const opened = oneEvent(el, 'sp-opened');
Expand Down
22 changes: 16 additions & 6 deletions packages/sidenav/test/sidenav.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
expect,
fixture,
html,
nextFrame,
waitUntil,
} from '@open-wc/testing';
import { LitElement, TemplateResult } from '@spectrum-web-components/base';
Expand Down Expand Up @@ -393,6 +394,11 @@ describe('Sidenav', () => {
it('focuses the child anchor not the root when [tabindex=-1]', async () => {
const el = await fixture<SideNav>(manageTabIndex());

await nextFrame();
await nextFrame();
await nextFrame();
await nextFrame();
Comment on lines +397 to +400
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why all the nextFrames here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is working to ensure that all child elements have el.updateComplete'ed. We would likely benefit from an advanced version of fixture or other helper that ensured whole tree of elements has updated before running tests.


await elementUpdated(el);
const firstItem = el.querySelector(
'[value="Section 0"]'
Expand All @@ -405,17 +411,21 @@ describe('Sidenav', () => {
await sendMouse({
steps: [
{
type: 'move',
position: [firstRect.x + 2, firstRect.y + 2],
},
{
type: 'down',
type: 'click',
position: [
firstRect.x + firstRect.width / 2,
firstRect.y + firstRect.height / 2,
],
},
],
});
await elementUpdated(el);

expect(firstItem.focusElement.matches(':focus')).to.be.true;
expect(firstItem.matches(':focus'), 'root has focus').to.be.true;
expect(
firstItem.focusElement.matches(':focus'),
'child has more precise focus'
).to.be.true;
});
it('manage tab index through shadow DOM', async () => {
class SideNavTestEl extends LitElement {
Expand Down
7 changes: 4 additions & 3 deletions packages/slider/src/HandleController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class HandleController {

public inputForHandle(handle: SliderHandle): HTMLInputElement | undefined {
if (this.handles.has(handle.handleName)) {
const { input } = this.getHandleElements(handle);
const { input } = this.getHandleElements(handle) || {};
return input;
}
/* c8 ignore next 2 */
Expand Down Expand Up @@ -161,8 +161,9 @@ export class HandleController {
public get focusElement(): HTMLElement {
const { input } = this.getActiveHandleElements();
if (
this.host.editable &&
!(input as InputWithModel).model.handle.dragging
!input ||
(this.host.editable &&
!(input as InputWithModel).model.handle.dragging)
) {
return this.host.numberField;
}
Expand Down
2 changes: 1 addition & 1 deletion projects/documentation/src/components/layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
CSSResultArray,
html,
LitElement,
nothing,
PropertyValues,
TemplateResult,
} from '@spectrum-web-components/base';
Expand Down Expand Up @@ -45,7 +46,6 @@ import './code-example.js';
import { copyText } from './copy-to-clipboard.js';

import layoutStyles from './layout.css';
import { nothing } from 'lit-html';
import {
DARK_MODE,
IS_MOBILE,
Expand Down
7 changes: 6 additions & 1 deletion projects/documentation/src/utils/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

import { css, CSSResultGroup, html, TemplateResult } from 'lit';
import {
css,
type CSSResultGroup,
html,
type TemplateResult,
} from '@spectrum-web-components/base';

export function toHtmlTemplateString(code: string): TemplateResult {
const stringArray = [`${code}`] as any;
Expand Down
2 changes: 1 addition & 1 deletion tools/base/src/sizedMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function SizedMixin<T extends Constructor<ReactiveElement>>(
} = {}
): T & Constructor<SizedElementInterface> {
class SizedElement extends constructor {
@property({ type: String, reflect: true })
@property({ type: String })
public get size(): ElementSize {
return this._size || defaultSize;
}
Expand Down
4 changes: 3 additions & 1 deletion tools/base/test/define-element.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ describe('define-element', function () {
const spyCall = this.warn.getCall(0);
expect(
(spyCall.args.at(0) as string).includes('redefine'),
'message should warn about redefining an element'
`message should warn about redefining an element, instead got "${spyCall.args.at(
0
)}"`
).to.be.true;
})
);
Expand Down
8 changes: 6 additions & 2 deletions tools/shared/src/focusable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,12 @@ export class Focusable extends FocusVisiblePolyfillMixin(SpectrumElement) {

private onPointerdownManagementOfTabIndex(): void {
if (this.tabIndex === -1) {
this.tabIndex = 0;
this.focus({ preventScroll: true });
setTimeout(() => {
// Ensure this happens _after_ WebKit attempts to focus the :host.
this.tabIndex = 0;
this.focus({ preventScroll: true });
this.tabIndex = -1;
});
}
}

Expand Down
Loading