Skip to content

Commit

Permalink
fixed shortkey accessKey and shortkey check in inputs
Browse files Browse the repository at this point in the history
Refs: #6251
  • Loading branch information
AlexanderSchmidtCE committed Oct 29, 2024
1 parent 4585c96 commit 7ec5b86
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 58 deletions.
9 changes: 5 additions & 4 deletions packages/components/src/components/combobox/shadow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
import {

Check warning on line 1 in packages/components/src/components/combobox/shadow.tsx

View workflow job for this annotation

GitHub Actions / build

Imports "ComboboxAPI", "ComboboxStates", "HideErrorPropType", "IdPropType", "InputTypeOnDefault", "KoliBriHorizontalIcons", "LabelWithExpertSlotPropType", "MsgPropType", "NamePropType", "ShortKeyPropType", "Stringified", "SuggestionsPropType", "SyncValueBySelectorPropType", "TooltipAlignPropType" and "W3CInputValue" are only used as type
buildBadgeText,
ComboboxAPI,
ComboboxStates,
HideErrorPropType,
Expand Down Expand Up @@ -176,11 +177,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' ? (
<>
<InternalUnderlinedBadgeText badgeText={this.state._accessKey ?? this.state._shortKey} label={this.state._label} />{' '}
<InternalUnderlinedBadgeText badgeText={buildBadgeText(this.state._accessKey, this.state._shortKey)} label={this.state._label} />{' '}
<span class="access-key-hint" aria-hidden="true">
{this.state._accessKey}
{buildBadgeText(this.state._accessKey, this.state._shortKey)}
</span>
</>
) : (
Expand Down
9 changes: 5 additions & 4 deletions packages/components/src/components/input-checkbox/shadow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
import {

Check warning on line 1 in packages/components/src/components/input-checkbox/shadow.tsx

View workflow job for this annotation

GitHub Actions / build

Imports "CheckedPropType", "HideErrorPropType", "IdPropType", "IndeterminatePropType", "InputCheckboxAPI", "InputCheckboxIconsProp", "InputCheckboxStates", "InputCheckboxVariant", "InputTypeOnDefault", "LabelAlignPropType", "LabelWithExpertSlotPropType", "MsgPropType", "NamePropType", "ShortKeyPropType", "StencilUnknown", "Stringified", "SyncValueBySelectorPropType" and "TooltipAlignPropType" are only used as type
buildBadgeText,
CheckedPropType,
HideErrorPropType,
IdPropType,
Expand Down Expand Up @@ -107,11 +108,11 @@ export class KolInputCheckbox implements InputCheckboxAPI, FocusableElement {
<span slot="label">
{hasExpertSlot ? (
<slot name="expert"></slot>
) : typeof this.state._accessKey === 'string' ? (
) : typeof this.state._accessKey === 'string' || typeof this.state._shortKey === 'string' ? (
<>
<InternalUnderlinedBadgeText badgeText={this.state._accessKey} label={this.state._label} />{' '}
<InternalUnderlinedBadgeText badgeText={buildBadgeText(this.state._accessKey, this.state._shortKey)} label={this.state._label} />{' '}
<span class="access-key-hint" aria-hidden="true">
{this.state._accessKey}
{buildBadgeText(this.state._accessKey || this.state._shortKey)}
</span>
</>
) : (
Expand Down
9 changes: 5 additions & 4 deletions packages/components/src/components/input-color/shadow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
import {

Check warning on line 1 in packages/components/src/components/input-color/shadow.tsx

View workflow job for this annotation

GitHub Actions / build

Imports "ButtonProps", "FocusableElement", "HideErrorPropType", "IdPropType", "InputColorAPI", "InputColorStates", "InputTypeOnDefault", "InputTypeOnOff", "KoliBriHorizontalIcons", "LabelWithExpertSlotPropType", "MsgPropType", "NamePropType", "ShortKeyPropType", "Stringified", "SuggestionsPropType", "SyncValueBySelectorPropType" and "TooltipAlignPropType" are only used as type
buildBadgeText,
ButtonProps,
FocusableElement,
HideErrorPropType,
Expand Down Expand Up @@ -100,11 +101,11 @@ export class KolInputColor implements InputColorAPI, FocusableElement {
<span slot="label">
{hasExpertSlot ? (
<slot name="expert"></slot>
) : typeof this.state._accessKey === 'string' ? (
) : typeof this.state._accessKey === 'string' || typeof this.state._shortKey === 'string' ? (
<>
<InternalUnderlinedBadgeText badgeText={this.state._accessKey ?? this.state._shortKey} label={this.state._label} />{' '}
<InternalUnderlinedBadgeText badgeText={buildBadgeText(this.state._accessKey, this.state._shortKey)} label={this.state._label} />{' '}
<span class="access-key-hint" aria-hidden="true">
{this.state._accessKey}
{buildBadgeText(this.state._accessKey, this.state._shortKey)}
</span>
</>
) : (
Expand Down
9 changes: 5 additions & 4 deletions packages/components/src/components/input-date/shadow.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { JSX } from '@stencil/core';
import { Component, Element, Fragment, h, Host, Method, Prop, State, Watch } from '@stencil/core';
import type {
import {

Check warning on line 3 in packages/components/src/components/input-date/shadow.tsx

View workflow job for this annotation

GitHub Actions / build

Imports "ButtonProps", "HideErrorPropType", "IdPropType", "InputDateAPI", "InputDateStates", "InputDateType", "InputTypeOnDefault", "InputTypeOnOff", "Iso8601", "KoliBriHorizontalIcons", "LabelWithExpertSlotPropType", "NamePropType", "ReadOnlyPropType", "ShortKeyPropType", "Stringified", "SuggestionsPropType", "SyncValueBySelectorPropType" and "TooltipAlignPropType" are only used as type
buildBadgeText,
ButtonProps,
HideErrorPropType,
IdPropType,
Expand Down Expand Up @@ -154,11 +155,11 @@ export class KolInputDate implements InputDateAPI, FocusableElement {
<span slot="label">
{hasExpertSlot ? (
<slot name="expert"></slot>
) : typeof this.state._accessKey === 'string' ? (
) : typeof this.state._accessKey === 'string' || typeof this.state._shortKey === 'string' ? (
<>
<InternalUnderlinedBadgeText badgeText={this.state._accessKey ?? this.state._shortKey} label={this.state._label} />{' '}
<InternalUnderlinedBadgeText badgeText={buildBadgeText(this.state._accessKey, this.state._shortKey)} label={this.state._label} />{' '}
<span class="access-key-hint" aria-hidden="true">
{this.state._accessKey}
{buildBadgeText(this.state._accessKey || this.state._shortKey)}
</span>
</>
) : (
Expand Down
9 changes: 5 additions & 4 deletions packages/components/src/components/input-email/shadow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
import {

Check warning on line 1 in packages/components/src/components/input-email/shadow.tsx

View workflow job for this annotation

GitHub Actions / build

Imports "ButtonProps", "FocusableElement", "HideErrorPropType", "IdPropType", "InputEmailAPI", "InputEmailStates", "InputTypeOnDefault", "InputTypeOnOff", "KoliBriHorizontalIcons", "LabelWithExpertSlotPropType", "MsgPropType", "MultiplePropType", "NamePropType", "ShortKeyPropType", "Stringified", "SuggestionsPropType", "SyncValueBySelectorPropType" and "TooltipAlignPropType" are only used as type
buildBadgeText,
ButtonProps,
FocusableElement,
HideErrorPropType,
Expand Down Expand Up @@ -123,11 +124,11 @@ export class KolInputEmail implements InputEmailAPI, FocusableElement {
<span slot="label">
{hasExpertSlot ? (
<slot name="expert"></slot>
) : typeof this.state._accessKey === 'string' ? (
) : typeof this.state._accessKey === 'string' || typeof this.state._shortKey === 'string' ? (
<>
<InternalUnderlinedBadgeText badgeText={this.state._accessKey ?? this.state._shortKey} label={this.state._label} />{' '}
<InternalUnderlinedBadgeText badgeText={buildBadgeText(this.state._accessKey, this.state._shortKey)} label={this.state._label} />{' '}
<span class="access-key-hint" aria-hidden="true">
{this.state._accessKey}
{buildBadgeText(this.state._accessKey, this.state._shortKey)}
</span>
</>
) : (
Expand Down
9 changes: 5 additions & 4 deletions packages/components/src/components/input-file/shadow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
import {

Check warning on line 1 in packages/components/src/components/input-file/shadow.tsx

View workflow job for this annotation

GitHub Actions / build

Imports "ButtonProps", "FocusableElement", "HideErrorPropType", "IdPropType", "InputFileAPI", "InputFileStates", "InputTypeOnDefault", "KoliBriHorizontalIcons", "LabelWithExpertSlotPropType", "MsgPropType", "NamePropType", "ShortKeyPropType", "Stringified", "SyncValueBySelectorPropType" and "TooltipAlignPropType" are only used as type
buildBadgeText,
ButtonProps,
FocusableElement,
HideErrorPropType,
Expand Down Expand Up @@ -97,11 +98,11 @@ export class KolInputFile implements InputFileAPI, FocusableElement {
<span slot="label">
{hasExpertSlot ? (
<slot name="expert"></slot>
) : typeof this.state._accessKey === 'string' ? (
) : typeof this.state._accessKey === 'string' || typeof this.state._shortKey === 'string' ? (
<>
<InternalUnderlinedBadgeText badgeText={this.state._accessKey ?? this.state._shortKey} label={this.state._label} />{' '}
<InternalUnderlinedBadgeText badgeText={buildBadgeText(this.state._accessKey, this.state._shortKey)} label={this.state._label} />{' '}
<span class="access-key-hint" aria-hidden="true">
{this.state._accessKey}
{buildBadgeText(this.state._accessKey, this.state._shortKey)}
</span>
</>
) : (
Expand Down
9 changes: 5 additions & 4 deletions packages/components/src/components/input-number/shadow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
import {

Check warning on line 1 in packages/components/src/components/input-number/shadow.tsx

View workflow job for this annotation

GitHub Actions / build

Imports "ButtonProps", "FocusableElement", "HideErrorPropType", "IdPropType", "InputNumberAPI", "InputNumberStates", "InputTypeOnDefault", "InputTypeOnOff", "Iso8601", "KoliBriHorizontalIcons", "LabelWithExpertSlotPropType", "MsgPropType", "NamePropType", "ShortKeyPropType", "Stringified", "SuggestionsPropType", "SyncValueBySelectorPropType" and "TooltipAlignPropType" are only used as type
buildBadgeText,
ButtonProps,
FocusableElement,
HideErrorPropType,
Expand Down Expand Up @@ -116,11 +117,11 @@ export class KolInputNumber implements InputNumberAPI, FocusableElement {
<span slot="label">
{hasExpertSlot ? (
<slot name="expert"></slot>
) : typeof this.state._accessKey === 'string' ? (
) : typeof this.state._accessKey === 'string' || typeof this.state._shortKey === 'string' ? (
<>
<InternalUnderlinedBadgeText badgeText={this.state._accessKey ?? this.state._shortKey} label={this.state._label} />{' '}
<InternalUnderlinedBadgeText badgeText={buildBadgeText(this.state._accessKey, this.state._shortKey)} label={this.state._label} />{' '}
<span class="access-key-hint" aria-hidden="true">
{this.state._accessKey}
{buildBadgeText(this.state._accessKey, this.state._shortKey)}
</span>
</>
) : (
Expand Down
9 changes: 5 additions & 4 deletions packages/components/src/components/input-password/shadow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
import {

Check warning on line 1 in packages/components/src/components/input-password/shadow.tsx

View workflow job for this annotation

GitHub Actions / build

Imports "ButtonProps", "FocusableElement", "HideErrorPropType", "IdPropType", "InputPasswordAPI", "InputPasswordStates", "InputTypeOnDefault", "InputTypeOnOff", "KoliBriHorizontalIcons", "LabelWithExpertSlotPropType", "MsgPropType", "NamePropType", "ShortKeyPropType", "Stringified", "SyncValueBySelectorPropType" and "TooltipAlignPropType" are only used as type
buildBadgeText,
ButtonProps,
FocusableElement,
HideErrorPropType,
Expand Down Expand Up @@ -124,11 +125,11 @@ export class KolInputPassword implements InputPasswordAPI, FocusableElement {
<span slot="label">
{hasExpertSlot ? (
<slot name="expert"></slot>
) : typeof this.state._accessKey === 'string' ? (
) : typeof this.state._accessKey === 'string' || typeof this.state._shortKey === 'string' ? (
<>
<InternalUnderlinedBadgeText badgeText={this.state._accessKey ?? this.state._shortKey} label={this.state._label} />{' '}
<InternalUnderlinedBadgeText badgeText={buildBadgeText(this.state._accessKey, this.state._shortKey)} label={this.state._label} />{' '}
<span class="access-key-hint" aria-hidden="true">
{this.state._accessKey}
{buildBadgeText(this.state._accessKey, this.state._shortKey)}
</span>
</>
) : (
Expand Down
7 changes: 4 additions & 3 deletions packages/components/src/components/input-radio/shadow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {
import {
FocusableElement,
HideErrorPropType,
IdPropType,
Expand All @@ -15,6 +15,7 @@ import type {
SyncValueBySelectorPropType,
TooltipAlignPropType,
ShortKeyPropType,
buildBadgeText,
} from '../../schema';
import { showExpertSlot } from '../../schema';
import type { JSX } from '@stencil/core';
Expand Down Expand Up @@ -94,8 +95,8 @@ export class KolInputRadio implements InputRadioAPI, FocusableElement {
<span slot="label">
{hasExpertSlot ? (
<slot name="expert"></slot>
) : typeof this._accessKey === 'string' ? (
<InternalUnderlinedBadgeText badgeText={this.state._accessKey ?? this.state._shortKey ?? ''} label={this._label} />
) : typeof this.state._accessKey === 'string' || typeof this.state._shortKey === 'string' ? (
<InternalUnderlinedBadgeText badgeText={buildBadgeText(this.state._accessKey, this.state._shortKey)} label={this._label} />
) : (
this._label
)}
Expand Down
9 changes: 5 additions & 4 deletions packages/components/src/components/input-range/shadow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
import {
buildBadgeText,
FocusableElement,
HideErrorPropType,
IdPropType,
Expand Down Expand Up @@ -147,11 +148,11 @@ export class KolInputRange implements InputRangeAPI, FocusableElement {
<span slot="label">
{hasExpertSlot ? (
<slot name="expert"></slot>
) : typeof this.state._accessKey === 'string' ? (
) : typeof this.state._accessKey === 'string' || typeof this.state._shortKey === 'string' ? (
<>
<InternalUnderlinedBadgeText badgeText={this.state._accessKey ?? this.state._shortKey} label={this.state._label} />{' '}
<InternalUnderlinedBadgeText badgeText={buildBadgeText(this.state._accessKey, this.state._shortKey)} label={this.state._label} />{' '}
<span class="access-key-hint" aria-hidden="true">
{this.state._accessKey}
{buildBadgeText(this.state._accessKey, this.state._shortKey)}
</span>
</>
) : (
Expand Down
9 changes: 5 additions & 4 deletions packages/components/src/components/input-text/shadow.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {
import {
AccessKeyPropType,
AlertPropType,
buildBadgeText,
ButtonProps,
FocusableElement,
HideErrorPropType,
Expand Down Expand Up @@ -136,11 +137,11 @@ export class KolInputText implements InputTextAPI, FocusableElement {
<span slot="label">
{hasExpertSlot ? (
<slot name="expert"></slot>
) : typeof this.state._accessKey === 'string' ? (
) : typeof this.state._accessKey === 'string' || typeof this.state._shortKey === 'string' ? (
<>
<InternalUnderlinedBadgeText badgeText={this.state._accessKey ?? this.state._shortKey} label={this.state._label} />{' '}
<InternalUnderlinedBadgeText badgeText={buildBadgeText(this.state._accessKey, this.state._shortKey)} label={this.state._label} />{' '}
<span class="access-key-hint" aria-hidden="true">
{this.state._accessKey}
{buildBadgeText(this.state._accessKey, this.state._shortKey)}
</span>
</>
) : (
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/components/input/component.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable jsx-a11y/label-has-associated-control */
import { handleSlotContent, type MsgPropType, type ShortKeyPropType, showExpertSlot } from '../../schema';
import { buildBadgeText, handleSlotContent, type MsgPropType, type ShortKeyPropType, showExpertSlot } from '../../schema';
import type { JSX } from '@stencil/core';
import { Component, Element, Fragment, Host, Prop, h } from '@stencil/core';
import clsx from 'clsx';
Expand Down Expand Up @@ -114,7 +114,7 @@ export class KolInputWc implements Props {
*/
aria-hidden="true"
class="input-tooltip"
_badgeText={this._accessKey || this._shortKey}
_badgeText={buildBadgeText(this._accessKey, this._shortKey)}
_align={this._tooltipAlign}
_id={this._hideLabel ? `${this._id}-label` : undefined}
_label={this._label}
Expand Down
9 changes: 5 additions & 4 deletions packages/components/src/components/select/shadow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
import {
buildBadgeText,
FocusableElement,
HideErrorPropType,
IdPropType,
Expand Down Expand Up @@ -130,11 +131,11 @@ export class KolSelect implements SelectAPI, FocusableElement {
<span slot="label">
{hasExpertSlot ? (
<slot name="expert"></slot>
) : typeof this.state._accessKey === 'string' ? (
) : typeof this.state._accessKey === 'string' || typeof this.state._shortKey === 'string' ? (
<>
<InternalUnderlinedBadgeText badgeText={this.state._accessKey ?? this.state._shortKey} label={this.state._label} />{' '}
<InternalUnderlinedBadgeText badgeText={buildBadgeText(this.state._accessKey, this.state._shortKey)} label={this.state._label} />{' '}
<span class="access-key-hint" aria-hidden="true">
{this.state._accessKey}
{buildBadgeText(this.state._accessKey, this.state._shortKey)}
</span>
</>
) : (
Expand Down
9 changes: 5 additions & 4 deletions packages/components/src/components/single-select/shadow.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
import {
buildBadgeText,
HideErrorPropType,
IdPropType,
InputTypeOnDefault,
Expand Down Expand Up @@ -201,11 +202,11 @@ export class KolSingleSelect implements SingleSelectAPI {
<span slot="label">
{hasExpertSlot ? (
<slot name="expert"></slot>
) : typeof this.state._accessKey === 'string' ? (
) : typeof this.state._accessKey === 'string' || typeof this.state._shortKey === 'string' ? (
<>
<InternalUnderlinedBadgeText badgeText={this.state._accessKey ?? this.state._shortKey} label={this.state._label} />{' '}
<InternalUnderlinedBadgeText badgeText={buildBadgeText(this.state._accessKey || this.state._shortKey)} label={this.state._label} />{' '}
<span class="access-key-hint" aria-hidden="true">
{this.state._accessKey}
{buildBadgeText(this.state._accessKey || this.state._shortKey)}
</span>
</>
) : (
Expand Down
9 changes: 5 additions & 4 deletions packages/components/src/components/textarea/shadow.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {
import {
AdjustHeightPropType,
buildBadgeText,
CSSResize,
FocusableElement,
HasCounterPropType,
Expand Down Expand Up @@ -113,11 +114,11 @@ export class KolTextarea implements TextareaAPI, FocusableElement {
<span slot="label">
{hasExpertSlot ? (
<slot name="expert"></slot>
) : typeof this.state._accessKey === 'string' ? (
) : typeof this.state._accessKey === 'string' || typeof this.state._shortKey === 'string' ? (
<>
<InternalUnderlinedBadgeText badgeText={this.state._accessKey ?? this.state._shortKey} label={this.state._label} />{' '}
<InternalUnderlinedBadgeText badgeText={buildBadgeText(this.state._accessKey || this.state._shortKey)} label={this.state._label} />{' '}
<span class="access-key-hint" aria-hidden="true">
{this.state._accessKey}
{buildBadgeText(this.state._accessKey || this.state._shortKey)}
</span>
</>
) : (
Expand Down
11 changes: 11 additions & 0 deletions packages/components/src/schema/utils/reuse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,14 @@ export const handleSlotContent = (hostRef: HTMLElement, slotRef: HTMLElement, sl
* @returns True if the label is an empty string
*/
export const showExpertSlot = (label: unknown) => label === '';

/**
* This function builds the BadgeText. It chooses access key over shortkey or empty string, if both are empty
* @param accessKey
* @param shortKey
* @returns returns badgeText as string
*/
export const buildBadgeText = (accessKey?: string, shortKey?: string) => {
const badgeText = [accessKey, shortKey].filter((f) => f);
return badgeText[0] || '';
};
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const InputNumberCases = forwardRef<HTMLKolInputNumberElement, Components
<KolInputNumber {...props} _readOnly _label="Number input (Readonly)" />
<KolInputNumber {...props} _disabled _label="Number input (Disabled)" />
<KolInputNumber {...props} _label="With access key" _accessKey="c" />
<KolInputNumber {...props} _label="With short key" _shortKey="c" />
<KolInputNumber {...props} _label="With short key" _shortKey="s" />
</div>
);
});

0 comments on commit 7ec5b86

Please sign in to comment.