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

fix(base,reactive-controllers): add delegates API and downstate delegate #4229

Open
wants to merge 207 commits into
base: main
Choose a base branch
from

Conversation

TarunAdobe
Copy link
Contributor

@TarunAdobe TarunAdobe commented Apr 1, 2024

Description

This PR adds the delegate strategy in SWC that allows us to add downstate functionality over our existing components. This is needed so that we can support features like downstate in Spectrum 2 while keeping everything as it is in Spectrum 1

Downstate Activation is added to this PR

Motivation and context

The downstate feature in spectrum-two enhances user interaction by providing visual feedback when components are clicked or activated. It improves accessibility and user experience by clearly indicating the active state of elements. Developers can enable downstate for components, and it seamlessly integrates with existing functionality in the framework. This addition enriches the user interface, making interactions more intuitive and engaging.

Technical Document

How has this been tested?

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (minor updates related to the tooling or maintenance of the repository, does not impact compiled assets)

Checklist

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • If my change required a change to the documentation, I have updated the documentation in this pull request.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have reviewed at the Accessibility Practices for this feature, see: Aria Practices

Best practices

This repository uses conventional commit syntax for each commit message; note that the GitHub UI does not use this by default so be cautious when accepting suggested changes. Avoid the "Update branch" button on the pull request and opt instead for rebasing your branch against main.

jnjosh and others added 19 commits March 15, 2024 11:51
* fix(slider): no change in background for variant filled and fill start

* chore(slider): updated readme for slider with fill start and variant filled

---------

Co-authored-by: Rajdeep Chandra <rajdeepchandra@Rajdeeps-MacBook-Pro-2.local>
Bumps [next](https://github.com/vercel/next.js) from 14.1.0 to 14.1.4.
- [Release notes](https://github.com/vercel/next.js/releases)
- [Changelog](https://github.com/vercel/next.js/blob/canary/release.js)
- [Commits](vercel/next.js@v14.1.0...v14.1.4)

---
updated-dependencies:
- dependency-name: next
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
@Rajdeepc Rajdeepc changed the title Delegate controllers feat(): added downstate delegate Apr 1, 2024
@Rajdeepc Rajdeepc changed the title feat(): added downstate delegate feat(): added downstate delegate for S2 Apr 1, 2024
@Rajdeepc Rajdeepc added the S2 label Apr 1, 2024
packages/button/src/ButtonBase.ts Outdated Show resolved Hide resolved
tools/base/src/Base.ts Outdated Show resolved Hide resolved
tools/reactive-controllers/src/SpectrumDelegates.ts Outdated Show resolved Hide resolved
@Rajdeepc Rajdeepc requested a review from Westbrook May 3, 2024 12:40
Copy link
Collaborator

@Westbrook Westbrook left a comment

Choose a reason for hiding this comment

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

Not so sure why there's churn in the lock. I've seen it in other branches lately, so it might be related to renovate bot, or this might not be fully up to date with main?

);
await nextFrame();
await nextFrame();
controller.handlePointerDown();
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should use sendMouse to trigger this, rather than address the method directly.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure! the directly call is removed with a sendMouse trigger to mimic the call!

import { html, LitElement } from 'lit';
import { DownState } from '@spectrum-web-components/reactive-controllers/src/downstate.js';

class TestDownstateEl extends LitElement {}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use spectrumConfig here to ensure both the Controller and the delegates approach?

Copy link
Collaborator

Choose a reason for hiding this comment

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

May also want to wrap it all in an <sp-theme> to get ALL of the contracts covered.

Copy link
Contributor

Choose a reason for hiding this comment

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

class TestDownstateEl extends SpectrumElement {
    override spectrumConfig = {
        downstate: ['spectrum-two'],
    };
    protected override render(): TemplateResult {
        return html`
            <sp-theme system="spectrum-two" color="light" scale="medium">
                <slot></slot>
            </sp-theme>
        `;
    }
}

Comment on lines 52 to 53
this.host?.removeEventListener('pointerdown', this.handlePointerDown);
this.host?.removeEventListener('pointerup', this.handlePointerUp);
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should remove the listeners with the abort signal.

Copy link
Contributor

Choose a reason for hiding this comment

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

removeEventListeners(): void {
        this.abortController.abort();
        this.host?.removeEventListener('pointerdown', this.handlePointerDown);
        this.host?.removeEventListener('pointerup', this.handlePointerUp);
    }

Copy link
Collaborator

Choose a reason for hiding this comment

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

The use of the abort controller here should prevent the need for removeEventListener code.

Comment on lines +56 to +62
public handlePointerDown = (): void => {
this.updateDownStateStyles(true);
};

public handlePointerUp = (): void => {
this.updateDownStateStyles(false);
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

This applies these changes synchronously, which is probably correct. However, the majority of our render reactions are async, due to the reactivity of LitElement. Do you se any issue with this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel updating the down state styles is a UI-specific operation and not directly related to LitElement's reactivity, handling it synchronously shouldn't cause any problems, but would love to hear your thoughts why you foresee some issues here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Less about issues than about normalization and expectations. It's probably of no matter other than how it should be explicitly tested in https://github.com/adobe/spectrum-web-components/pull/4229/files/e9ea73081b0593fd29df23b1c67b00de68700cfb#r1589155295

Copy link
Contributor

Choose a reason for hiding this comment

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

This has been updated!

tools/reactive-controllers/src/downstate.ts Show resolved Hide resolved
@Rajdeepc Rajdeepc requested review from Westbrook, jnjosh and Rajdeepc and removed request for blunteshwar and Rajdeepc May 8, 2024 07:55
@Rajdeepc Rajdeepc force-pushed the swc-s2-styles branch 2 times, most recently from 6ca339b to 33c5c24 Compare May 13, 2024 12:28
Base automatically changed from swc-s2-styles to main May 14, 2024 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

S2: add downstate functionality in spectrum-two
6 participants