Skip to content

Commit

Permalink
Added ShortKey Prop to Elements with AccessKey (#6957)
Browse files Browse the repository at this point in the history
  • Loading branch information
deleonio authored Nov 14, 2024
2 parents 2a5064b + 371e250 commit 223ee80
Show file tree
Hide file tree
Showing 165 changed files with 1,374 additions and 234 deletions.
17 changes: 15 additions & 2 deletions packages/components/src/components/@deprecated/input/controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import type { Generic } from 'adopted-style-sheets';

import type {
AccessKeyPropType,
AdjustHeightPropType,
ButtonProps,
HideErrorPropType,
InputTypeOnDefault,
LabelWithExpertSlotPropType,
MsgPropType,
ShortKeyPropType,
StencilUnknown,
Stringified,
TooltipAlignPropType,
Expand All @@ -18,6 +20,7 @@ import {
objectObjectHandler,
parseJson,
setState,
validateAccessKey,
validateAdjustHeight,
validateHideError,
validateHideLabel,
Expand All @@ -27,13 +30,15 @@ import {
validateTooltipAlign,
watchBoolean,
watchString,
validateShortKey,
} from '../../../schema';

import { stopPropagation, tryToDispatchKoliBriEvent } from '../../../utils/events';
import { ControlledInputController } from '../../input-adapter-leanup/controller';

import type { Props as AdapterProps } from '../../input-adapter-leanup/types';
import type { Props, Watches } from './types';
import { validateAccessAndShortKey } from '../../../schema/validators/access-and-short-key';

type ValueChangeListener = (value: StencilUnknown) => void;

Expand All @@ -47,8 +52,9 @@ export class InputController extends ControlledInputController implements Watche
this.component = component;
}

public validateAccessKey(value?: string): void {
watchString(this.component, '_accessKey', value);
public validateAccessKey(value?: AccessKeyPropType): void {
validateAccessKey(this.component, value);
validateAccessAndShortKey(value, this.component._shortKey);
}

public validateAdjustHeight(value?: AdjustHeightPropType): void {
Expand Down Expand Up @@ -127,6 +133,11 @@ export class InputController extends ControlledInputController implements Watche
}
}

public validateShortKey(value?: ShortKeyPropType): void {
validateShortKey(this.component, value);
validateAccessAndShortKey(this.component._accessKey, value);
}

public validateSmartButton(value?: ButtonProps | string): void {
objectObjectHandler(value, () => {
try {
Expand Down Expand Up @@ -155,9 +166,11 @@ export class InputController extends ControlledInputController implements Watche
this.validateHint(this.component._hint);
this.validateId(this.component._id);
this.validateLabel(this.component._label);
this.validateShortKey(this.component._shortKey);
this.validateSmartButton(this.component._smartButton);
this.validateOn(this.component._on);
this.validateTabIndex(this.component._tabIndex);
validateAccessAndShortKey(this.component._accessKey, this.component._shortKey);
}

protected onBlur(event: Event): void {
Expand Down
5 changes: 3 additions & 2 deletions packages/components/src/components/@deprecated/input/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { ButtonProps, InputTypeOnDefault, MsgPropType, PropLabelWithExpertSlot, Stringified } from '../../../schema';
import type { AccessKeyPropType, ButtonProps, InputTypeOnDefault, MsgPropType, PropLabelWithExpertSlot, ShortKeyPropType, Stringified } from '../../../schema';
import type { Generic } from 'adopted-style-sheets';

type RequiredProps = NonNullable<unknown>;
type OptionalProps = PropLabelWithExpertSlot & {
accessKey: string;
accessKey: AccessKeyPropType;
adjustHeight: boolean;
disabled: boolean;
error: string;
Expand All @@ -13,6 +13,7 @@ type OptionalProps = PropLabelWithExpertSlot & {
id: string;
msg: MsgPropType;
on: InputTypeOnDefault;
shortKey: ShortKeyPropType;
smartButton: Stringified<ButtonProps>;
syncValueBySelector: string;
tabIndex: number;
Expand Down
7 changes: 7 additions & 0 deletions packages/components/src/components/button-link/shadow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
IdPropType,
LabelWithExpertSlotPropType,
NamePropType,
ShortKeyPropType,
StencilUnknown,
Stringified,
SyncValueBySelectorPropType,
Expand Down Expand Up @@ -72,6 +73,7 @@ export class KolButtonLink implements ButtonLinkProps, FocusableElement {
_name={this._name}
_on={this._on}
_role="link"
_shortKey={this._shortKey}
_syncValueBySelector={this._syncValueBySelector}
_tabIndex={this._tabIndex}
_tooltipAlign={this._tooltipAlign}
Expand Down Expand Up @@ -154,6 +156,11 @@ export class KolButtonLink implements ButtonLinkProps, FocusableElement {
*/
@Prop() public _role?: AlternativeButtonLinkRolePropType;

/**
* Adds a visual short key hint to the component.
*/
@Prop() public _shortKey?: ShortKeyPropType;

/**
* Selector for synchronizing the value with another input element.
* @internal
Expand Down
21 changes: 19 additions & 2 deletions packages/components/src/components/button/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
FocusableElement,
IconsPropType,
LabelWithExpertSlotPropType,
ShortKeyPropType,
StencilUnknown,
Stringified,
SyncValueBySelectorPropType,
Expand All @@ -37,6 +38,7 @@ import {
validateHideLabel,
validateIcons,
validateLabelWithExpertSlot,
validateShortKey,
validateTabIndex,
validateTooltipAlign,
watchString,
Expand All @@ -49,6 +51,7 @@ import { nonce } from '../../utils/dev.utils';
import { propagateResetEventToForm, propagateSubmitEventToForm } from '../form/controller';
import { AssociatedInputController } from '../input-adapter-leanup/associated.controller';
import { KolSpanWcTag, KolTooltipWcTag } from '../../core/component-names';
import { validateAccessAndShortKey } from '../../schema/validators/access-and-short-key';

/**
* @internal
Expand Down Expand Up @@ -134,7 +137,7 @@ export class KolButtonWc implements ButtonAPI, FocusableElement {
>
<KolSpanWcTag
class="button-inner"
_accessKey={this.state._accessKey}
_badgeText={this.state._accessKey || this.state._shortKey}
_icons={this.state._icons}
_hideLabel={this.state._hideLabel}
_label={hasExpertSlot ? '' : this.state._label}
Expand All @@ -149,7 +152,7 @@ export class KolButtonWc implements ButtonAPI, FocusableElement {
*/
aria-hidden="true"
hidden={hasExpertSlot || !this.state._hideLabel}
_accessKey={this._accessKey}
_badgeText={this.state._accessKey || this.state._shortKey}
_align={this.state._tooltipAlign}
_label={typeof this.state._label === 'string' ? this.state._label : ''}
></KolTooltipWcTag>
Expand Down Expand Up @@ -236,6 +239,11 @@ export class KolButtonWc implements ButtonAPI, FocusableElement {
*/
@Prop() public _role?: AlternativeButtonLinkRolePropType;

/**
* Adds a visual short key hint to the component.
*/
@Prop() public _shortKey?: ShortKeyPropType;

/**
* Selector for synchronizing the value with another input element.
* @internal
Expand Down Expand Up @@ -282,6 +290,7 @@ export class KolButtonWc implements ButtonAPI, FocusableElement {
@Watch('_accessKey')
public validateAccessKey(value?: AccessKeyPropType): void {
validateAccessKey(this, value);
validateAccessAndShortKey(value, this._shortKey);
}

@Watch('_ariaControls')
Expand Down Expand Up @@ -351,6 +360,12 @@ export class KolButtonWc implements ButtonAPI, FocusableElement {
validateAlternativeButtonLinkRole(this, value);
}

@Watch('_shortKey')
public validateShortKey(value?: ShortKeyPropType): void {
validateShortKey(this, value);
validateAccessAndShortKey(this._accessKey, value);
}

@Watch('_syncValueBySelector')
public validateSyncValueBySelector(value?: SyncValueBySelectorPropType): void {
this.controller.validateSyncValueBySelector(value);
Expand Down Expand Up @@ -397,11 +412,13 @@ export class KolButtonWc implements ButtonAPI, FocusableElement {
this.validateName(this._name);
this.validateOn(this._on);
this.validateRole(this._role);
this.validateShortKey(this._shortKey);
this.validateSyncValueBySelector(this._syncValueBySelector);
this.validateTabIndex(this._tabIndex);
this.validateTooltipAlign(this._tooltipAlign);
this.validateType(this._type);
this.validateValue(this._value);
this.validateVariant(this._variant);
validateAccessAndShortKey(this._accessKey, this._shortKey);
}
}
7 changes: 7 additions & 0 deletions packages/components/src/components/button/shadow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
FocusableElement,
IconsPropType,
LabelWithExpertSlotPropType,
ShortKeyPropType,
StencilUnknown,
Stringified,
SyncValueBySelectorPropType,
Expand Down Expand Up @@ -78,6 +79,7 @@ export class KolButton implements ButtonProps, FocusableElement {
_name={this._name}
_on={this._on}
_role={this._role}
_shortKey={this._shortKey}
_syncValueBySelector={this._syncValueBySelector}
_tabIndex={this._tabIndex}
_tooltipAlign={this._tooltipAlign}
Expand Down Expand Up @@ -163,6 +165,11 @@ export class KolButton implements ButtonProps, FocusableElement {
*/
@Prop() public _role?: AlternativeButtonLinkRolePropType;

/**
* Defines the elements short key.
*/
@Prop() public _shortKey?: ShortKeyPropType;

/**
* Selector for synchronizing the value with another input element.
* @internal
Expand Down
22 changes: 17 additions & 5 deletions packages/components/src/components/combobox/shadow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@ import type {
LabelWithExpertSlotPropType,
MsgPropType,
NamePropType,
ShortKeyPropType,
Stringified,
SuggestionsPropType,
SyncValueBySelectorPropType,
TooltipAlignPropType,
W3CInputValue,
} from '../../schema';
import { showExpertSlot } from '../../schema';
import { buildBadgeTextString, showExpertSlot } from '../../schema';
import type { JSX } from '@stencil/core';
import { Component, Element, Fragment, h, Host, Listen, Method, Prop, State, Watch } from '@stencil/core';

import { nonce } from '../../utils/dev.utils';
import { stopPropagation, tryToDispatchKoliBriEvent } from '../../utils/events';
import { ComboboxController } from './controller';
import { KolIconTag, KolInputTag } from '../../core/component-names';
import { InternalUnderlinedAccessKey } from '../span/InternalUnderlinedAccessKey';
import { InternalUnderlinedBadgeText } from '../span/InternalUnderlinedBadgeText';
import { getRenderStates } from '../input/controller';
import { translate } from '../../i18n';
import clsx from 'clsx';
Expand Down Expand Up @@ -166,6 +167,7 @@ export class KolCombobox implements ComboboxAPI {
_label={this.state._label}
_msg={this.state._msg}
_required={this.state._required}
_shortKey={this.state._shortKey}
_tooltipAlign={this._tooltipAlign}
_touched={this.state._touched}
onClick={() => this.refInput?.focus()}
Expand All @@ -174,11 +176,11 @@ export class KolCombobox implements ComboboxAPI {
<span slot="label">
{hasExpertSlot ? (
<slot name="expert"></slot>
) : typeof this.state._accessKey === 'string' ? (
) : typeof this.state._accessKey === 'string' || typeof this.state._shortKey === 'string' ? (
<>
<InternalUnderlinedAccessKey accessKey={this.state._accessKey} label={this.state._label} />{' '}
<InternalUnderlinedBadgeText badgeText={buildBadgeTextString(this.state._accessKey, this.state._shortKey)} label={this.state._label} />{' '}
<span class="access-key-hint" aria-hidden="true">
{this.state._accessKey}
{buildBadgeTextString(this.state._accessKey, this.state._shortKey)}
</span>
</>
) : (
Expand Down Expand Up @@ -445,6 +447,11 @@ export class KolCombobox implements ComboboxAPI {
*/
@Prop() public _required?: boolean = false;

/**
* Adds a visual short key hint to the component.
*/
@Prop() public _shortKey?: ShortKeyPropType;

/**
* Selector for synchronizing the value with another input element.
* @internal
Expand Down Expand Up @@ -560,6 +567,11 @@ export class KolCombobox implements ComboboxAPI {
this.controller.validateOn(value);
}

@Watch('_shortKey')
public validateShortKey(value?: ShortKeyPropType): void {
this.controller.validateShortKey(value);
}

@Watch('_suggestions')
public validateSuggestions(value?: SuggestionsPropType): void {
this.controller.validateSuggestions(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,31 @@ exports[`kol-combobox should render with _label="Label" _name="field" _placehold
</kol-combobox>
`;
exports[`kol-combobox should render with _label="Label" _name="field" _placeholder="Hier steht ein Platzhaltertext" _value="Herr" _suggestions=["Frau","Herr","Divers"] _shortKey="S" 1`] = `
<kol-combobox class="kol-combobox">
<template shadowrootmode="open">
<div class="combobox">
<kol-input _hint="" _id="id-nonce" _label="Label" _shortkey="S" _tooltipalign="top" role="presentation">
<span slot="label">
Label
<span aria-hidden="true" class="access-key-hint">
S
</span>
</span>
<div slot="input">
<div class="combobox__group">
<input aria-autocomplete="both" aria-controls="listbox" aria-expanded="false" aria-labelledby="id-nonce" autocapitalize="off" autocorrect="off" class="combobox__input" id="id-nonce" name="field" placeholder="Hier steht ein Platzhaltertext" role="combobox" spellcheck="false" type="text" value="Herr">
<button class="combobox__icon" tabindex="-1">
<kol-icon _icons="codicon codicon-triangle-down" _label="kol-dropdown"></kol-icon>
</button>
</div>
</div>
</kol-input>
</div>
</template>
</kol-combobox>
`;
exports[`kol-combobox should render with _label="Label" _name="field" _placeholder="Hier steht ein Platzhaltertext" _value="Herr" _suggestions=["Frau","Herr","Divers"] _touched=true 1`] = `
<kol-combobox _touched="" class="kol-combobox">
<template shadowrootmode="open">
Expand Down
Loading

0 comments on commit 223ee80

Please sign in to comment.