Skip to content

Commit

Permalink
chore(ui5-icon): update focus handling (#8773)
Browse files Browse the repository at this point in the history
Adjusted `ui5-icon` focus display rules. On desktop, focus outline is
always visible. For mobile, focus outline only appears with an external
keyboard, it remains hidden for touch focus.

Related to: #8320
  • Loading branch information
kgogov authored Apr 16, 2024
1 parent d30f424 commit db37cf8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 25 deletions.
2 changes: 0 additions & 2 deletions packages/main/src/Icon.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
aria-label="{{effectiveAccessibleName}}"
aria-hidden={{effectiveAriaHidden}}
xmlns="http://www.w3.org/2000/svg"
@focusin={{_onfocusin}}
@focusout={{_onfocusout}}
@keydown={{_onkeydown}}
@keyup={{_onkeyup}}
>
Expand Down
29 changes: 7 additions & 22 deletions packages/main/src/Icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import property from "@ui5/webcomponents-base/dist/decorators/property.js";
import { getIconData, getIconDataSync, IconData } from "@ui5/webcomponents-base/dist/asset-registries/Icons.js";
import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
import type { I18nText } from "@ui5/webcomponents-base/dist/i18nBundle.js";
import { isDesktop } from "@ui5/webcomponents-base/dist/Device.js";
import { isSpace, isEnter } from "@ui5/webcomponents-base/dist/Keys.js";
import executeTemplate from "@ui5/webcomponents-base/dist/renderer/executeTemplate.js";
import IconTemplate from "./generated/templates/IconTemplate.lit.js";
Expand Down Expand Up @@ -208,12 +209,6 @@ class Icon extends UI5Element implements IIcon {
@property({ type: Object, defaultValue: undefined, noAttribute: true })
accData?: I18nText;

/**
* @private
*/
@property({ type: Boolean })
focused!: boolean;

/**
* @private
*/
Expand All @@ -231,19 +226,6 @@ class Icon extends UI5Element implements IIcon {
viewBox?: string;
customSvg?: object;

_onfocusout?: ((event: FocusEvent) => void);
_onfocusin?: ((event: FocusEvent) => void);

_onFocusInHandler() {
if (this.interactive) {
this.focused = true;
}
}

_onFocusOutHandler() {
this.focused = false;
}

_onkeydown(e: KeyboardEvent) {
if (!this.interactive) {
return;
Expand Down Expand Up @@ -303,6 +285,12 @@ class Icon extends UI5Element implements IIcon {
return this.effectiveAccessibleName ? "img" : PRESENTATION_ROLE;
}

onEnterDOM() {
if (isDesktop()) {
this.setAttribute("desktop", "");
}
}

async onBeforeRendering() {
const name = this.name;
if (!name) {
Expand Down Expand Up @@ -341,9 +329,6 @@ class Icon extends UI5Element implements IIcon {
this.ltr = iconData.ltr;
this.packageName = iconData.packageName;

this._onfocusout = this.interactive ? this._onFocusOutHandler.bind(this) : undefined;
this._onfocusin = this.interactive ? this._onFocusInHandler.bind(this) : undefined;

if (this.accessibleName) {
this.effectiveAccessibleName = this.accessibleName;
} else if (this.accData) {
Expand Down
3 changes: 2 additions & 1 deletion packages/main/src/themes/Icon.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
color: var(--sapPositiveElementColor);
}

:host([interactive][focused]) .ui5-icon-root {
:host([interactive][desktop]) .ui5-icon-root:focus-within,
:host([interactive]) .ui5-icon-root:focus-visible {
outline: var(--sapContent_FocusWidth) var(--sapContent_FocusStyle) var(--sapContent_FocusColor);
border-radius: var(--ui5-icon-focus-border-radius);
}
Expand Down

0 comments on commit db37cf8

Please sign in to comment.