Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

fix(core:styles): cleanup focus css prop #6396

Merged
merged 1 commit into from
Oct 12, 2021

Conversation

coryrylan
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • If applicable, have a visual design approval

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • clarity.design website / infrastructure changes
  • Other... Please describe:

What is the new behavior?

This is some work I am pulling out of the datagrid branch. This adds the native focus outline as a token value to help make the outline usage consistent within components. This also adds a focus outline state demo for the interaction examples in storybook.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@coryrylan coryrylan self-assigned this Oct 11, 2021
@@ -120,7 +119,7 @@ export class CdsButton extends CdsBaseButton {
</div>`;
}

static styles = [baseStyles, baseButtonStyles, styles];
static styles = [baseStyles, styles];
Copy link
Contributor Author

@coryrylan coryrylan Oct 11, 2021

Choose a reason for hiding this comment

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

I combined base button styles and the buttons styles int a single style sheet. Icon button inherits button styles from the button element.

static styles = [baseStyles, baseButtonStyles, styles];
static get styles() {
return [super.styles, styles];
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rather than generate the base button css twice just inherit from the button

width: var(--cds-alias-object-interaction-touch-target);
height: var(--cds-alias-object-interaction-touch-target);
cursor: var(--cursor);
}
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 ensures the inline controls (checkbox, radio, switch) get the appropriate standard focus outline and minimum touch target size

@@ -59,7 +59,8 @@ export class CdsInternalControlInline extends CdsControl {
? 'order:reverse'
: ''}"
>
<div class="input" @click=${this.selectInput}></div>
<div role="presentation" class="input" @click=${this.selectInput}></div>
<div role="presentation" focusable @click=${this.selectInput}></div>
Copy link
Contributor Author

@coryrylan coryrylan Oct 11, 2021

Choose a reason for hiding this comment

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

This fixes an a11y bug where the SR can get confused on treating the click handler as an interactive group rather than focusing to the native slotted checkbox or radio input.

position: relative;
--width: #{$cds-global-space-7};
--height: #{$cds-global-space-7};
--cds-alias-object-interaction-touch-target: #{$cds-global-space-8};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sets a minimum touch target for inline elements like radio/checkbox. Also useful for datagrid to align target/focus to cell easily.

--outline: var(--cds-alias-object-interaction-outline);
--outline-offset: var(--cds-alias-object-interaction-outline-offset);
--cds-alias-object-interaction-outline: none;
--cds-alias-object-interaction-outline-offset: 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Input overrides the default outline since it uses the underline focus effect. However I still use the variable so its consistent with theming and can be adjusted like any other component.

Signed-off-by: Cory Rylan <splintercode.cb@gmail.com>
@@ -1,244 +0,0 @@
// Copyright (c) 2016-2021 VMware, Inc. All Rights Reserved.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we deleting base button?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. I was confused. I thought we were deleting base-button.element.ts...

@@ -96,6 +96,7 @@ export class CdsAccordionPanel extends LitElement implements Animatable {
?disabled="${this.disabled}"
aria-disabled="${this.disabled}"
aria-expanded="${this.expanded}"
focusable
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this focusable attribute work in React when users need to assign boolean values?

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 in particular is internal in the shadow dom so no consumer would access/use it. It is for making it easy to apply the focus element styles internal to our templates.

outline: 0 !important;
}

[focusable] {
Copy link
Contributor

@Shijir Shijir Oct 12, 2021

Choose a reason for hiding this comment

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

Related question. I remember for boolean attributes, I needed to specify [focusable]=true/false in React. I wonder if that applies here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as the other example, this is internal to the template. It doesnt use::slotted so its not applying as part of the public API. If its a property of the component React can set it like any other property however if its a plain html attribute (@property was not used in the web component) then users will run into this problem facebook/react#9230

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. Thanks for the explanation.

@coryrylan coryrylan merged commit 7bf82fc into vmware-archive:next Oct 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants