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(ui5-color-palette*): add mobile focus for external input devices #9770

Merged
merged 4 commits into from
Oct 5, 2024
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
6 changes: 6 additions & 0 deletions packages/main/src/ColorPaletteItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js";
import { isPhone } from "@ui5/webcomponents-base/dist/Device.js";
import { getScopedVarName } from "@ui5/webcomponents-base/dist/CustomElementsScopeUtils.js";
import type { IColorPaletteItem } from "./ColorPalette.js";
import ColorPaletteItemTemplate from "./generated/templates/ColorPaletteItemTemplate.lit.js";
import {
Expand All @@ -31,6 +32,7 @@ import ColorPaletteItemCss from "./generated/themes/ColorPaletteItem.css.js";
renderer: litRender,
styles: ColorPaletteItemCss,
template: ColorPaletteItemTemplate,
shadowRootOptions: { delegatesFocus: true },
})
class ColorPaletteItem extends UI5Element implements IColorPaletteItem {
/**
Expand Down Expand Up @@ -98,6 +100,10 @@ class ColorPaletteItem extends UI5Element implements IColorPaletteItem {
this._disabled = !this.value;
this.onPhone = isPhone();
this.setAttribute("style", `background-color: ${this.value}`);

// since height is dynamically determined by padding-block-start
const itemHeight = this.offsetHeight + 4; // adding 4px for the offsets on top and bottom
this.style.setProperty(getScopedVarName("--_ui5_color_palette_item_height"), `${itemHeight}px`);
}

get colorLabel() {
Expand Down
7 changes: 7 additions & 0 deletions packages/main/src/ColorPalettePopover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
import { getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js";
import DOMReferenceConverter from "@ui5/webcomponents-base/dist/converters/DOMReference.js";
import { getScopedVarName } from "@ui5/webcomponents-base/dist/CustomElementsScopeUtils.js";
import ColorPalettePopoverTemplate from "./generated/templates/ColorPalettePopoverTemplate.lit.js";

// Styles
Expand Down Expand Up @@ -185,6 +186,12 @@ class ColorPalettePopover extends UI5Element {
} else if (colorPalette.showDefaultColor) {
colorPalette.colorPaletteNavigationElements[0].focus();
}

// since height is dynamically determined by padding-block-start
colorPalette.allColorsInPalette.forEach((item: IColorPaletteItem) => {
const itemHeight = item.offsetHeight + 4; // adding 4px for the offsets on top and bottom
item.style.setProperty(getScopedVarName("--_ui5_color_palette_item_height"), `${itemHeight}px`);
});
}

onSelectedColor(e: CustomEvent<ColorPaletteItemClickEventDetail>) {
Expand Down
24 changes: 23 additions & 1 deletion packages/main/src/themes/ColorPaletteItem.css
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@

:host([selected]:not([_disabled]):not([on-phone]):not(:focus):not(:hover)) .ui5-cp-item::after,
:host([selected]:not([_disabled]):not([on-phone]):not(:focus):hover) .ui5-cp-item::after,
:host(:not([selected]):hover) .ui5-cp-item::after {
:host(:not([selected]):not([on-phone]):hover) .ui5-cp-item::after {
content: "";
box-sizing: border-box;
position: absolute;
Expand All @@ -135,4 +135,26 @@
border: var(--_ui5_color-palette-item-before-focus-color);
border-radius: var(--_ui5_color-palette-item-before-focus-border-radius);
pointer-events: none;
}

/* Focus on mobile ONLY with external keyboard/mouse */
:host(:not([disabled])) .ui5-cp-item:focus-visible::before,
:host(:not([disabled])) .ui5-cp-item:focus-visible::after {
content: "";
box-sizing: border-box;
position: absolute;
pointer-events: none;
}

:host(:not([disabled])) .ui5-cp-item:focus-visible::before {
inset: calc(100% - var(--_ui5_color_palette_item_height) + var(--_ui5-color-palette-item-mobile-focus-inset))
var(--_ui5_color-palette-item-mobile-focus-sides-inset);
border: var(--_ui5_color-palette-item-before-focus-color);
border-radius: var(--_ui5_color-palette-item-after-focus-border-radius);
}

:host(:not([disabled])) .ui5-cp-item:focus-visible::after {
inset: calc(100% - var(--_ui5_color_palette_item_height) + var(--_ui5-color-palette-item-mobile-focus-inset))
var(--_ui5_color-palette-item-mobile-focus-sides-inset);
border: var(--_ui5_color-palette-item-after-mobile-focus-border);
}
3 changes: 3 additions & 0 deletions packages/main/src/themes/base/ColorPalette-parameters.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@
--_ui5_color-palette-item-after-focus-not-selected-border: 0.0625rem dotted black;
--_ui5_color-palette-item-after-not-focus-color: 0.0625rem solid var(--sapGroup_ContentBackground);
--_ui5_color-palette-item-selected-focused-border: 0.0625rem solid var(--sapGroup_ContentBackground);
--_ui5-color-palette-item-mobile-focus-inset: 0.625rem;
--_ui5_color-palette-item-mobile-focus-sides-inset: 0.25rem 0.25rem;
--_ui5_color-palette-item-after-mobile-focus-border: var(--_ui5_color-palette-item-after-focus-color);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@
--_ui5_color-palette-item-selected-focused-border-before: -0.0625rem;
--_ui5_color-palette-item-after-focus-not-selected-border: none;
--_ui5_color-palette-item-selected-focused-border: none;
--_ui5_color-palette-item-mobile-focus-sides-inset: -0.375rem -0.375rem;
--_ui5-color-palette-item-mobile-focus-inset: 0px;
--_ui5_color-palette-item-after-mobile-focus-border: none;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@
--_ui5_color-palette-item-selected-focused-border-before: -0.0625rem;
--_ui5_color-palette-item-after-focus-not-selected-border: none;
--_ui5_color-palette-item-selected-focused-border: none;
--_ui5_color-palette-item-after-mobile-focus-border: none;
--_ui5-color-palette-item-mobile-focus-inset: 0px;
--_ui5_color-palette-item-mobile-focus-sides-inset: -0.375rem -0.375rem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@
--_ui5_color-palette-item-hover-inner-border-radius: 0.375rem;
--_ui5_color-palette-item-after-focus-not-selected-border: none;
--_ui5_color-palette-item-selected-focused-border: none;
--_ui5_color-palette-item-after-mobile-focus-border: none;
--_ui5-color-palette-item-mobile-focus-inset: 0px;
--_ui5_color-palette-item-mobile-focus-sides-inset: -0.375rem -0.375rem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@
--_ui5_color-palette-item-hover-inner-border-radius: 0.375rem;
--_ui5_color-palette-item-after-focus-not-selected-border: none;
--_ui5_color-palette-item-selected-focused-border: none;
--_ui5_color-palette-item-after-mobile-focus-border: none;
--_ui5-color-palette-item-mobile-focus-inset: 0px;
--_ui5_color-palette-item-mobile-focus-sides-inset: -0.375rem -0.375rem;
}