From 7cf1ab2c49112375a7c62f70e663b4d114d5c95c Mon Sep 17 00:00:00 2001 From: Raisa Primerova Date: Mon, 15 Jun 2026 16:51:22 -0600 Subject: [PATCH 01/10] feat: Add KBD component to labs --- modules/labs-react/index.ts | 1 + modules/labs-react/kbd/LICENSE | 52 ++++++++++++ modules/labs-react/kbd/README.md | 11 +++ modules/labs-react/kbd/index.ts | 2 + modules/labs-react/kbd/lib/KBD.tsx | 82 +++++++++++++++++++ modules/labs-react/kbd/lib/KBDItem.tsx | 28 +++++++ modules/labs-react/kbd/spec/SSR.spec.tsx | 19 +++++ modules/labs-react/kbd/spec/tsconfig.json | 4 + modules/labs-react/kbd/stories/KBD.mdx | 42 ++++++++++ .../labs-react/kbd/stories/KBD.stories.tsx | 23 ++++++ .../labs-react/kbd/stories/examples/Basic.tsx | 20 +++++ .../labs-react/kbd/stories/examples/RTL.tsx | 19 +++++ modules/labs-react/kbd/stories/tsconfig.json | 4 + .../visual-testing/testing.stories.tsx | 46 +++++++++++ 14 files changed, 353 insertions(+) create mode 100644 modules/labs-react/kbd/LICENSE create mode 100644 modules/labs-react/kbd/README.md create mode 100644 modules/labs-react/kbd/index.ts create mode 100644 modules/labs-react/kbd/lib/KBD.tsx create mode 100644 modules/labs-react/kbd/lib/KBDItem.tsx create mode 100644 modules/labs-react/kbd/spec/SSR.spec.tsx create mode 100644 modules/labs-react/kbd/spec/tsconfig.json create mode 100644 modules/labs-react/kbd/stories/KBD.mdx create mode 100644 modules/labs-react/kbd/stories/KBD.stories.tsx create mode 100644 modules/labs-react/kbd/stories/examples/Basic.tsx create mode 100644 modules/labs-react/kbd/stories/examples/RTL.tsx create mode 100644 modules/labs-react/kbd/stories/tsconfig.json create mode 100644 modules/labs-react/kbd/stories/visual-testing/testing.stories.tsx diff --git a/modules/labs-react/index.ts b/modules/labs-react/index.ts index ed625199bf..936652a59f 100644 --- a/modules/labs-react/index.ts +++ b/modules/labs-react/index.ts @@ -1,2 +1,3 @@ export * from './ai-ingress-button'; +export * from './kbd'; export * from './version'; diff --git a/modules/labs-react/kbd/LICENSE b/modules/labs-react/kbd/LICENSE new file mode 100644 index 0000000000..10966086f1 --- /dev/null +++ b/modules/labs-react/kbd/LICENSE @@ -0,0 +1,52 @@ +Apache License, Version 2.0 Apache License Version 2.0, January 2004 + +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. +Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. +You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: +You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. +Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. +This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. +Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. +In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. +While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +©2021 Workday, Inc. All rights reserved. Workday and the Workday logo are registered trademarks of Workday, Inc. All other brand and product names are trademarks or registered trademarks of their respective holders. + + +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. diff --git a/modules/labs-react/kbd/README.md b/modules/labs-react/kbd/README.md new file mode 100644 index 0000000000..b46974a751 --- /dev/null +++ b/modules/labs-react/kbd/README.md @@ -0,0 +1,11 @@ +# Canvas Kit KBD + + + LABS: Alpha + This component is work in progress and currently in prerelease. + +A compound component used to visually represent keyboard input, such as keys or keyboard shortcuts. + +View the +[documentation for KBD](https://workday.github.io/canvas-kit/?path=/docs/labs-kbd--docs) +on Storybook. diff --git a/modules/labs-react/kbd/index.ts b/modules/labs-react/kbd/index.ts new file mode 100644 index 0000000000..43b8bdf91f --- /dev/null +++ b/modules/labs-react/kbd/index.ts @@ -0,0 +1,2 @@ +export * from './lib/KBD'; +export * from './lib/KBDItem'; diff --git a/modules/labs-react/kbd/lib/KBD.tsx b/modules/labs-react/kbd/lib/KBD.tsx new file mode 100644 index 0000000000..7fb4bb0af3 --- /dev/null +++ b/modules/labs-react/kbd/lib/KBD.tsx @@ -0,0 +1,82 @@ +import React from 'react'; + +import {createComponent} from '@workday/canvas-kit-react/common'; +import {CSProps, createStencil, handleCsProp} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; + +import {KBDItem} from './KBDItem'; + +export interface KBDProps extends CSProps { + /** + * The variant of the `KBD` keys. + * @default 'default' + */ + variant?: 'ghost' | 'default'; + /** + * The children of the `KBD` container. This should contain one or more `KBD.Item` components that + * each represent a single keyboard key. + */ + children?: React.ReactNode; +} + +export const kbdStencil = createStencil({ + parts: { + item: 'kbd-item', + }, + base: ({itemPart}) => ({ + display: 'inline-flex', + alignItems: 'center', + gap: system.gap.xs, + [itemPart]: { + ...system.type.subtext.lg, + cornerShape: 'superellipse(1.1)', + borderRadius: system.sana.shape.sm, + textAlign: 'center', + }, + }), + modifiers: { + variant: { + ghost: ({itemPart}) => ({ + [itemPart]: { + backgroundColor: system.legacy.color.surface.transparent, + }, + }), + default: ({itemPart}) => ({ + [itemPart]: { + backgroundColor: system.sana.color.surface.alt.default, + padding: system.padding.xxs, + minWidth: system.size.xxs, + }, + }), + }, + }, +}); + +/** + * `KBD` is a container component used to visually represent keyboard input, such as keys or + * keyboard shortcuts. It renders as a semantic `kbd` element and wraps one or more `KBD.Item` + * components. + * + * ```tsx + * + * + * C + * + * ``` + */ +export const KBD = createComponent('kbd')({ + displayName: 'KBD', + subComponents: { + /** + * `KBD.Item` renders a single keyboard key as a semantic `kbd` element. + */ + Item: KBDItem, + }, + Component: ({variant = 'default', children, ...elemProps}: KBDProps, ref, Element) => { + return ( + + {children} + + ); + }, +}); diff --git a/modules/labs-react/kbd/lib/KBDItem.tsx b/modules/labs-react/kbd/lib/KBDItem.tsx new file mode 100644 index 0000000000..8746a70810 --- /dev/null +++ b/modules/labs-react/kbd/lib/KBDItem.tsx @@ -0,0 +1,28 @@ +import React from 'react'; + +import {createComponent} from '@workday/canvas-kit-react/common'; +import {CSProps, handleCsProp} from '@workday/canvas-kit-styling'; + +import {kbdStencil} from './KBD'; + +export interface KBDItemProps extends CSProps { + /** + * The content of the key. This should be the label of a single keyboard key (e.g. `Ctrl`, `⌘`, + * `Enter`). + */ + children?: React.ReactNode; +} + +/** + * `KBD.Item` renders a single keyboard key as a semantic `kbd` element. + */ +export const KBDItem = createComponent('kbd')({ + displayName: 'KBD.Item', + Component: ({children, ...elemProps}: KBDItemProps, ref, Element) => { + return ( + + {children} + + ); + }, +}); diff --git a/modules/labs-react/kbd/spec/SSR.spec.tsx b/modules/labs-react/kbd/spec/SSR.spec.tsx new file mode 100644 index 0000000000..3101a19b7b --- /dev/null +++ b/modules/labs-react/kbd/spec/SSR.spec.tsx @@ -0,0 +1,19 @@ +/** + * @jest-environment node + */ +import {renderToString} from 'react-dom/server'; + +import {KBD} from '../lib/KBD'; + +describe('KBD', () => { + it('should render on a server without crashing', () => { + const ssrRender = () => + renderToString( + + Ctrl + C + + ); + expect(ssrRender).not.toThrow(); + }); +}); diff --git a/modules/labs-react/kbd/spec/tsconfig.json b/modules/labs-react/kbd/spec/tsconfig.json new file mode 100644 index 0000000000..d079d9f251 --- /dev/null +++ b/modules/labs-react/kbd/spec/tsconfig.json @@ -0,0 +1,4 @@ + +{ + "extends": "../../../../tsconfig.spec.json" +} diff --git a/modules/labs-react/kbd/stories/KBD.mdx b/modules/labs-react/kbd/stories/KBD.mdx new file mode 100644 index 0000000000..0bb680f6bd --- /dev/null +++ b/modules/labs-react/kbd/stories/KBD.mdx @@ -0,0 +1,42 @@ +import {Meta} from '@storybook/blocks'; + +import {ExampleCodeBlock, SymbolDoc} from '@workday/canvas-kit-docs'; + +import {KBD} from '@workday/canvas-kit-labs-react/kbd'; + +import KBDStoriesMeta from './KBD.stories'; +import {Basic} from './examples/Basic'; +import {RTL} from './examples/RTL'; + + + +# KBD + +`KBD` is a compound component used to visually represent keyboard input, such as keys or keyboard +shortcuts. + +## Installation + +```sh +yarn add @workday/canvas-kit-labs-react +``` + +## Usage + +### Basic Example + +`KBD` is a container that wraps one or more `KBD.Item` components. Each `KBD.Item` represents a +single keyboard key. + + + +### RTL Example + +You can also use the `KBD` component in right-to-left (RTL) layouts. This is helpful for languages +that are read from right to left. + + + +## Component API + + diff --git a/modules/labs-react/kbd/stories/KBD.stories.tsx b/modules/labs-react/kbd/stories/KBD.stories.tsx new file mode 100644 index 0000000000..b498146632 --- /dev/null +++ b/modules/labs-react/kbd/stories/KBD.stories.tsx @@ -0,0 +1,23 @@ +import {Meta} from '@storybook/react'; + +import mdxDoc from './KBD.mdx'; +import {Basic as BasicExample} from './examples/Basic'; +import {RTL as RTLExample} from './examples/RTL'; + +export default { + title: 'Labs/KBD', + tags: ['autodocs'], + parameters: { + docs: { + page: mdxDoc, + }, + }, +} as Meta; + +export const Basic = { + render: BasicExample, +}; + +export const RTL = { + render: RTLExample, +}; diff --git a/modules/labs-react/kbd/stories/examples/Basic.tsx b/modules/labs-react/kbd/stories/examples/Basic.tsx new file mode 100644 index 0000000000..684b619576 --- /dev/null +++ b/modules/labs-react/kbd/stories/examples/Basic.tsx @@ -0,0 +1,20 @@ +import {KBD} from '@workday/canvas-kit-labs-react/kbd'; +import {Flex} from '@workday/canvas-kit-react/layout'; +import {system} from '@workday/canvas-tokens-web'; + +export const Basic = () => { + return ( + + + + + C + + + Shift + + + A + + + ); +}; diff --git a/modules/labs-react/kbd/stories/examples/RTL.tsx b/modules/labs-react/kbd/stories/examples/RTL.tsx new file mode 100644 index 0000000000..2dc163f08f --- /dev/null +++ b/modules/labs-react/kbd/stories/examples/RTL.tsx @@ -0,0 +1,19 @@ +import {KBD} from '@workday/canvas-kit-labs-react/kbd'; +import {Flex} from '@workday/canvas-kit-react/layout'; +import {system} from '@workday/canvas-tokens-web'; + +export const RTL = () => { + return ( + + + + C + + + Shift + + + A + + + ); +}; diff --git a/modules/labs-react/kbd/stories/tsconfig.json b/modules/labs-react/kbd/stories/tsconfig.json new file mode 100644 index 0000000000..721d5175e2 --- /dev/null +++ b/modules/labs-react/kbd/stories/tsconfig.json @@ -0,0 +1,4 @@ + +{ + "extends": "../../../../tsconfig.stories.json" +} diff --git a/modules/labs-react/kbd/stories/visual-testing/testing.stories.tsx b/modules/labs-react/kbd/stories/visual-testing/testing.stories.tsx new file mode 100644 index 0000000000..b81817787f --- /dev/null +++ b/modules/labs-react/kbd/stories/visual-testing/testing.stories.tsx @@ -0,0 +1,46 @@ +import {KBD} from '@workday/canvas-kit-labs-react/kbd'; +import { + ComponentStatesTable, + StaticStates, + permutateProps, +} from '@workday/canvas-kit-react/testing'; +import {createStyles} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; + +export default { + title: 'Testing/Labs/KBD', + component: KBD, + parameters: { + chromatic: { + disable: false, + }, + }, +}; + +const darkBackground = createStyles({ + background: system.color.surface.alt.default, + padding: system.padding.xxl, +}); + +export const KBDStates = () => ( + + + {props => ( +
+ + + C + +
+ )} +
+
+); From b7a0c03c26cc4843fa5b8016e95205f81ccc2ffe Mon Sep 17 00:00:00 2001 From: Raisa Primerova Date: Tue, 23 Jun 2026 09:19:56 -0600 Subject: [PATCH 02/10] feat: Update KBD based on design spec --- modules/labs-react/kbd/lib/KBD.tsx | 94 ++++++++++++++++--- modules/labs-react/kbd/stories/KBD.mdx | 16 ++++ .../labs-react/kbd/stories/KBD.stories.tsx | 10 ++ .../labs-react/kbd/stories/examples/Basic.tsx | 29 ++++-- .../labs-react/kbd/stories/examples/RTL.tsx | 21 +++-- .../labs-react/kbd/stories/examples/Size.tsx | 49 ++++++++++ .../kbd/stories/examples/Variant.tsx | 42 +++++++++ .../visual-testing/testing.stories.tsx | 16 +++- 8 files changed, 242 insertions(+), 35 deletions(-) create mode 100644 modules/labs-react/kbd/stories/examples/Size.tsx create mode 100644 modules/labs-react/kbd/stories/examples/Variant.tsx diff --git a/modules/labs-react/kbd/lib/KBD.tsx b/modules/labs-react/kbd/lib/KBD.tsx index 7fb4bb0af3..1df6342897 100644 --- a/modules/labs-react/kbd/lib/KBD.tsx +++ b/modules/labs-react/kbd/lib/KBD.tsx @@ -1,22 +1,27 @@ import React from 'react'; import {createComponent} from '@workday/canvas-kit-react/common'; -import {CSProps, createStencil, handleCsProp} from '@workday/canvas-kit-styling'; +import {CSProps, createStencil, handleCsProp, px2rem} from '@workday/canvas-kit-styling'; import {system} from '@workday/canvas-tokens-web'; import {KBDItem} from './KBDItem'; export interface KBDProps extends CSProps { - /** - * The variant of the `KBD` keys. - * @default 'default' - */ - variant?: 'ghost' | 'default'; /** * The children of the `KBD` container. This should contain one or more `KBD.Item` components that * each represent a single keyboard key. */ children?: React.ReactNode; + /** + * The size of the `KBD` container. + * @default 'medium' + */ + size?: 'small' | 'medium' | 'large'; + /** + * The variant of the `KBD` keys. + * @default 'default' + */ + variant?: 'plain' | 'default'; } export const kbdStencil = createStencil({ @@ -26,30 +31,85 @@ export const kbdStencil = createStencil({ base: ({itemPart}) => ({ display: 'inline-flex', alignItems: 'center', - gap: system.gap.xs, + gap: system.legacy.gap.xs, [itemPart]: { - ...system.type.subtext.lg, - cornerShape: 'superellipse(1.1)', - borderRadius: system.sana.shape.sm, textAlign: 'center', }, }), modifiers: { variant: { - ghost: ({itemPart}) => ({ + plain: ({itemPart}) => ({ [itemPart]: { backgroundColor: system.legacy.color.surface.transparent, + color: system.color.fg.muted.default, + padding: 0, }, }), default: ({itemPart}) => ({ [itemPart]: { backgroundColor: system.sana.color.surface.alt.default, - padding: system.padding.xxs, - minWidth: system.size.xxs, + color: system.color.fg.muted.strong, + borderRadius: system.sana.shape.sm, + cornerShape: 'superellipse(1.1)', + }, + }), + }, + size: { + large: ({itemPart}) => ({ + [itemPart]: { + ...system.type.subtext.lg, + }, + }), + medium: ({itemPart}) => ({ + [itemPart]: { + ...system.type.subtext.md, + }, + }), + small: ({itemPart}) => ({ + [itemPart]: { + ...system.type.subtext.sm, }, }), }, }, + compound: [ + { + modifiers: { + size: 'large', + variant: 'default', + }, + styles: ({itemPart}) => ({ + [itemPart]: { + minWidth: system.legacy.size.xs, + padding: `${px2rem(2)} ${system.legacy.padding.xxs}`, + }, + }), + }, + { + modifiers: { + size: 'medium', + variant: 'default', + }, + styles: ({itemPart}) => ({ + [itemPart]: { + minWidth: system.legacy.size.xxs, + padding: `${px2rem(2)} ${system.legacy.padding.xxs}`, + }, + }), + }, + { + modifiers: { + size: 'small', + variant: 'default', + }, + styles: ({itemPart}) => ({ + [itemPart]: { + minWidth: system.legacy.size.xxxs, + padding: px2rem(2), + }, + }), + }, + ], }); /** @@ -72,9 +132,13 @@ export const KBD = createComponent('kbd')({ */ Item: KBDItem, }, - Component: ({variant = 'default', children, ...elemProps}: KBDProps, ref, Element) => { + Component: ( + {variant = 'default', size = 'medium', children, ...elemProps}: KBDProps, + ref, + Element + ) => { return ( - + {children} ); diff --git a/modules/labs-react/kbd/stories/KBD.mdx b/modules/labs-react/kbd/stories/KBD.mdx index 0bb680f6bd..64a4923c27 100644 --- a/modules/labs-react/kbd/stories/KBD.mdx +++ b/modules/labs-react/kbd/stories/KBD.mdx @@ -7,6 +7,8 @@ import {KBD} from '@workday/canvas-kit-labs-react/kbd'; import KBDStoriesMeta from './KBD.stories'; import {Basic} from './examples/Basic'; import {RTL} from './examples/RTL'; +import {Size} from './examples/Size'; +import {Variant} from './examples/Variant'; @@ -37,6 +39,20 @@ that are read from right to left. +### Size + +The `KBD` component supports different sizes. You can adjust the size using the `size` prop with +options like `small`, `medium`, and `large` to suit various UI needs. + + + +### Variant + +The `KBD` component supports different variants through the `variant` prop. Use `default` for the +standard style or `plain` for a more minimal appearance. + + + ## Component API diff --git a/modules/labs-react/kbd/stories/KBD.stories.tsx b/modules/labs-react/kbd/stories/KBD.stories.tsx index b498146632..9b6fa3ab2a 100644 --- a/modules/labs-react/kbd/stories/KBD.stories.tsx +++ b/modules/labs-react/kbd/stories/KBD.stories.tsx @@ -3,6 +3,8 @@ import {Meta} from '@storybook/react'; import mdxDoc from './KBD.mdx'; import {Basic as BasicExample} from './examples/Basic'; import {RTL as RTLExample} from './examples/RTL'; +import {Size as SizeExample} from './examples/Size'; +import {Variant as VariantExample} from './examples/Variant'; export default { title: 'Labs/KBD', @@ -21,3 +23,11 @@ export const Basic = { export const RTL = { render: RTLExample, }; + +export const Size = { + render: SizeExample, +}; + +export const Variant = { + render: VariantExample, +}; diff --git a/modules/labs-react/kbd/stories/examples/Basic.tsx b/modules/labs-react/kbd/stories/examples/Basic.tsx index 684b619576..8380e4a511 100644 --- a/modules/labs-react/kbd/stories/examples/Basic.tsx +++ b/modules/labs-react/kbd/stories/examples/Basic.tsx @@ -1,20 +1,31 @@ import {KBD} from '@workday/canvas-kit-labs-react/kbd'; -import {Flex} from '@workday/canvas-kit-react/layout'; +import {BodyText} from '@workday/canvas-kit-react/text'; +import {createStyles} from '@workday/canvas-kit-styling'; import {system} from '@workday/canvas-tokens-web'; +const containerStyles = createStyles({ + gap: system.gap.md, + display: 'flex', + flexDirection: 'column', +}); + export const Basic = () => { return ( - - +
+ + Press + + F + + to pay respects. + + - C - - Shift - + - A + + Shift + P - +
); }; diff --git a/modules/labs-react/kbd/stories/examples/RTL.tsx b/modules/labs-react/kbd/stories/examples/RTL.tsx index 2dc163f08f..fe5302fa71 100644 --- a/modules/labs-react/kbd/stories/examples/RTL.tsx +++ b/modules/labs-react/kbd/stories/examples/RTL.tsx @@ -1,19 +1,28 @@ import {KBD} from '@workday/canvas-kit-labs-react/kbd'; -import {Flex} from '@workday/canvas-kit-react/layout'; +import {createStyles} from '@workday/canvas-kit-styling'; import {system} from '@workday/canvas-tokens-web'; +const containerStyles = createStyles({ + gap: system.gap.md, + display: 'flex', + flexDirection: 'column', +}); + export const RTL = () => { return ( - - +
+ + F + + C - + Shift + - A + P - +
); }; diff --git a/modules/labs-react/kbd/stories/examples/Size.tsx b/modules/labs-react/kbd/stories/examples/Size.tsx new file mode 100644 index 0000000000..2b8f8661e0 --- /dev/null +++ b/modules/labs-react/kbd/stories/examples/Size.tsx @@ -0,0 +1,49 @@ +import {KBD} from '@workday/canvas-kit-labs-react/kbd'; +import {Subtext} from '@workday/canvas-kit-react/text'; +import {createStyles, px2rem} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; + +const containerStyles = createStyles({ + gap: system.gap.md, + display: 'flex', + flexDirection: 'column', +}); + +const rowStyles = createStyles({ + display: 'flex', + alignItems: 'center', + gap: system.gap.md, + p: { + minWidth: px2rem(104), + margin: 0, + }, +}); + +export const Size = () => { + return ( +
+
+ Large Size + + + C + +
+
+ Medium Size + + Shift + + + A + +
+
+ Small Size + + Ctrl + V + +
+
+ ); +}; diff --git a/modules/labs-react/kbd/stories/examples/Variant.tsx b/modules/labs-react/kbd/stories/examples/Variant.tsx new file mode 100644 index 0000000000..9d8ba5ce61 --- /dev/null +++ b/modules/labs-react/kbd/stories/examples/Variant.tsx @@ -0,0 +1,42 @@ +import {KBD} from '@workday/canvas-kit-labs-react/kbd'; +import {Subtext} from '@workday/canvas-kit-react/text'; +import {createStyles, px2rem} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; + +const containerStyles = createStyles({ + gap: system.gap.md, + display: 'flex', + flexDirection: 'column', + p: { + minWidth: px2rem(104), + margin: 0, + }, +}); + +const rowStyles = createStyles({ + display: 'flex', + alignItems: 'center', + gap: system.gap.md, +}); + +export const Variant = () => { + return ( +
+
+ Default Variant + + + C + +
+
+ Plain Variant + + Shift + + + A + +
+
+ ); +}; diff --git a/modules/labs-react/kbd/stories/visual-testing/testing.stories.tsx b/modules/labs-react/kbd/stories/visual-testing/testing.stories.tsx index b81817787f..cde0d7ffd2 100644 --- a/modules/labs-react/kbd/stories/visual-testing/testing.stories.tsx +++ b/modules/labs-react/kbd/stories/visual-testing/testing.stories.tsx @@ -19,7 +19,7 @@ export default { const darkBackground = createStyles({ background: system.color.surface.alt.default, - padding: system.padding.xxl, + padding: system.padding.xs, }); export const KBDStates = () => ( @@ -27,14 +27,20 @@ export const KBDStates = () => ( {props => ( -
+
C From 3fa7775100690b57773419f6254d455bb1a3b375 Mon Sep 17 00:00:00 2001 From: Raisa Primerova Date: Tue, 23 Jun 2026 09:31:24 -0600 Subject: [PATCH 03/10] docs: Add note to upgrade guide --- modules/docs/mdx/16.0-UPGRADE-GUIDE.mdx | 31 ++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/modules/docs/mdx/16.0-UPGRADE-GUIDE.mdx b/modules/docs/mdx/16.0-UPGRADE-GUIDE.mdx index 2ae1d3c43e..b61f0d18da 100644 --- a/modules/docs/mdx/16.0-UPGRADE-GUIDE.mdx +++ b/modules/docs/mdx/16.0-UPGRADE-GUIDE.mdx @@ -17,6 +17,7 @@ Soon to be... - [Codemod](#codemod) - [Instructions](#instructions) - [New Components](#new-components) + - [KBD](#kbd) - [Component Updates](#component-updates) - [Deprecations](#deprecations) - [Glossary](#glossary) @@ -86,7 +87,35 @@ yarn remove @workday/canvas-kit-codemod ## New Components -[Content will be added] +### KBD + +**PR:** [#4001](https://github.com/Workday/canvas-kit/pull/4001) + +The new `KBD` component allows you to display keyboard inputs in your UI using accessible, visually +consistent keyboard key representations. This is useful for documenting keyboard shortcuts, +instructional prompts, or any UI patterns that reference specific keys. + +**Highlights:** + +- Provides a semantic and accessible way to present keyboard keys and shortcuts to users. +- Supports various variants (`default` for prominence, `plain` for use on colored surfaces), as well + as size options (`small`, `medium`, `large`). +- Easy to use nested `KBD.Item` components for sequences or combinations. +- RTL support. + +**Example:** + +```tsx +import {KBD} from '@workday/canvas-kit-labs-react'; + + + + C +; +``` + +For more details and advanced usage, refer to the storybook documentation and our example stories +(e.g. for RTL, variants, and testing). ## Component Updates From 311736c9e5030e40e964819c348c7a2a40777cd3 Mon Sep 17 00:00:00 2001 From: Raisa Primerova Date: Tue, 23 Jun 2026 09:57:54 -0600 Subject: [PATCH 04/10] fix: Add rtl note --- modules/labs-react/kbd/lib/KBDItem.tsx | 3 +-- modules/labs-react/kbd/stories/KBD.mdx | 7 +++++++ modules/labs-react/kbd/stories/examples/Basic.tsx | 4 +++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/modules/labs-react/kbd/lib/KBDItem.tsx b/modules/labs-react/kbd/lib/KBDItem.tsx index 8746a70810..418cbd686a 100644 --- a/modules/labs-react/kbd/lib/KBDItem.tsx +++ b/modules/labs-react/kbd/lib/KBDItem.tsx @@ -1,10 +1,9 @@ import React from 'react'; +import {kbdStencil} from '@workday/canvas-kit-labs-react/kbd'; import {createComponent} from '@workday/canvas-kit-react/common'; import {CSProps, handleCsProp} from '@workday/canvas-kit-styling'; -import {kbdStencil} from './KBD'; - export interface KBDItemProps extends CSProps { /** * The content of the key. This should be the label of a single keyboard key (e.g. `Ctrl`, `⌘`, diff --git a/modules/labs-react/kbd/stories/KBD.mdx b/modules/labs-react/kbd/stories/KBD.mdx index 64a4923c27..3c76072fa2 100644 --- a/modules/labs-react/kbd/stories/KBD.mdx +++ b/modules/labs-react/kbd/stories/KBD.mdx @@ -30,6 +30,13 @@ yarn add @workday/canvas-kit-labs-react `KBD` is a container that wraps one or more `KBD.Item` components. Each `KBD.Item` represents a single keyboard key. +> **Important:** When displaying a group of keyboard keys (such as Ctrl + C), +> **do not** combine them into a single `KBD.Item` (for example, `Ctrl + C`). +> Doing so will cause issues with RTL (right-to-left) positioning and keyboard shortcut display. +> +> Instead, wrap each key in its own `KBD.Item` and group them inside a `KBD` container. This ensures +> correct rendering and layout in both LTR and RTL environments. + ### RTL Example diff --git a/modules/labs-react/kbd/stories/examples/Basic.tsx b/modules/labs-react/kbd/stories/examples/Basic.tsx index 8380e4a511..7ccd01b660 100644 --- a/modules/labs-react/kbd/stories/examples/Basic.tsx +++ b/modules/labs-react/kbd/stories/examples/Basic.tsx @@ -24,7 +24,9 @@ export const Basic = () => { C - Shift + P + Shift + + + P
); From cda70ad0d6a2693bc29104b81c74175392c2185f Mon Sep 17 00:00:00 2001 From: Raisa Primerova Date: Wed, 24 Jun 2026 14:30:05 -0600 Subject: [PATCH 05/10] feat: Update KBD component --- modules/labs-react/kbd/index.ts | 1 + modules/labs-react/kbd/lib/KBD.tsx | 149 ++++++------------ modules/labs-react/kbd/lib/KBDItem.tsx | 89 +++++++++-- modules/labs-react/kbd/lib/useKBDModel.tsx | 56 +++++++ modules/labs-react/kbd/stories/KBD.mdx | 43 ++++- .../labs-react/kbd/stories/KBD.stories.tsx | 5 + .../labs-react/kbd/stories/examples/Basic.tsx | 9 ++ .../labs-react/kbd/stories/examples/Items.tsx | 19 +++ .../labs-react/kbd/stories/examples/RTL.tsx | 9 ++ .../visual-testing/testing.stories.tsx | 15 +- 10 files changed, 271 insertions(+), 124 deletions(-) create mode 100644 modules/labs-react/kbd/lib/useKBDModel.tsx create mode 100644 modules/labs-react/kbd/stories/examples/Items.tsx diff --git a/modules/labs-react/kbd/index.ts b/modules/labs-react/kbd/index.ts index 43b8bdf91f..d1427c0fa0 100644 --- a/modules/labs-react/kbd/index.ts +++ b/modules/labs-react/kbd/index.ts @@ -1,2 +1,3 @@ export * from './lib/KBD'; export * from './lib/KBDItem'; +export * from './lib/useKBDModel'; diff --git a/modules/labs-react/kbd/lib/KBD.tsx b/modules/labs-react/kbd/lib/KBD.tsx index 1df6342897..2398f9f13b 100644 --- a/modules/labs-react/kbd/lib/KBD.tsx +++ b/modules/labs-react/kbd/lib/KBD.tsx @@ -1,121 +1,75 @@ import React from 'react'; -import {createComponent} from '@workday/canvas-kit-react/common'; -import {CSProps, createStencil, handleCsProp, px2rem} from '@workday/canvas-kit-styling'; +import {useListRenderItems} from '@workday/canvas-kit-react/collection'; +import {createContainer} from '@workday/canvas-kit-react/common'; +import {CSProps, createStencil, handleCsProp} from '@workday/canvas-kit-styling'; import {system} from '@workday/canvas-tokens-web'; import {KBDItem} from './KBDItem'; +import {useKBDModel} from './useKBDModel'; export interface KBDProps extends CSProps { /** * The children of the `KBD` container. This should contain one or more `KBD.Item` components that - * each represent a single keyboard key. + * each represent a single keyboard key. If `items` are provided to the model, this should be a + * render prop that returns a `KBD.Item` for each item. + * + * @example + * // static + * + * + * C + * + * + * @example + * // dynamic + * + * {item => {item}} + * */ - children?: React.ReactNode; - /** - * The size of the `KBD` container. - * @default 'medium' - */ - size?: 'small' | 'medium' | 'large'; - /** - * The variant of the `KBD` keys. - * @default 'default' - */ - variant?: 'plain' | 'default'; + children?: React.ReactNode | ((item: string) => React.ReactNode); } export const kbdStencil = createStencil({ - parts: { - item: 'kbd-item', - }, - base: ({itemPart}) => ({ + base: { display: 'inline-flex', alignItems: 'center', gap: system.legacy.gap.xs, - [itemPart]: { - textAlign: 'center', - }, - }), + }, modifiers: { variant: { - plain: ({itemPart}) => ({ - [itemPart]: { - backgroundColor: system.legacy.color.surface.transparent, - color: system.color.fg.muted.default, - padding: 0, - }, - }), - default: ({itemPart}) => ({ - [itemPart]: { - backgroundColor: system.sana.color.surface.alt.default, - color: system.color.fg.muted.strong, - borderRadius: system.sana.shape.sm, - cornerShape: 'superellipse(1.1)', - }, - }), + plain: { + color: system.color.fg.muted.default, + }, + default: { + color: system.color.fg.muted.strong, + }, }, size: { - large: ({itemPart}) => ({ - [itemPart]: { + large: { + span: { ...system.type.subtext.lg, }, - }), - medium: ({itemPart}) => ({ - [itemPart]: { - ...system.type.subtext.md, - }, - }), - small: ({itemPart}) => ({ - [itemPart]: { - ...system.type.subtext.sm, - }, - }), - }, - }, - compound: [ - { - modifiers: { - size: 'large', - variant: 'default', }, - styles: ({itemPart}) => ({ - [itemPart]: { - minWidth: system.legacy.size.xs, - padding: `${px2rem(2)} ${system.legacy.padding.xxs}`, + medium: { + span: { + ...system.type.subtext.md, }, - }), - }, - { - modifiers: { - size: 'medium', - variant: 'default', }, - styles: ({itemPart}) => ({ - [itemPart]: { - minWidth: system.legacy.size.xxs, - padding: `${px2rem(2)} ${system.legacy.padding.xxs}`, + small: { + span: { + ...system.type.subtext.sm, }, - }), - }, - { - modifiers: { - size: 'small', - variant: 'default', }, - styles: ({itemPart}) => ({ - [itemPart]: { - minWidth: system.legacy.size.xxxs, - padding: px2rem(2), - }, - }), }, - ], + }, }); /** * `KBD` is a container component used to visually represent keyboard input, such as keys or * keyboard shortcuts. It renders as a semantic `kbd` element and wraps one or more `KBD.Item` - * components. + * components. It is responsible for creating a {@link useKBDModel} and sharing the `size` and + * `variant` with its `KBD.Item` subcomponents. * * ```tsx * @@ -124,23 +78,24 @@ export const kbdStencil = createStencil({ * * ``` */ -export const KBD = createComponent('kbd')({ +export const KBD = createContainer('kbd')({ displayName: 'KBD', + modelHook: useKBDModel, subComponents: { /** * `KBD.Item` renders a single keyboard key as a semantic `kbd` element. */ Item: KBDItem, }, - Component: ( - {variant = 'default', size = 'medium', children, ...elemProps}: KBDProps, - ref, - Element - ) => { - return ( - - {children} - - ); - }, +})(({children, ...elemProps}, Element, model) => { + return ( + + {useListRenderItems(model, children)} + + ); }); diff --git a/modules/labs-react/kbd/lib/KBDItem.tsx b/modules/labs-react/kbd/lib/KBDItem.tsx index 418cbd686a..b2f874898e 100644 --- a/modules/labs-react/kbd/lib/KBDItem.tsx +++ b/modules/labs-react/kbd/lib/KBDItem.tsx @@ -1,8 +1,11 @@ import React from 'react'; -import {kbdStencil} from '@workday/canvas-kit-labs-react/kbd'; -import {createComponent} from '@workday/canvas-kit-react/common'; -import {CSProps, handleCsProp} from '@workday/canvas-kit-styling'; +import {useListItemRegister} from '@workday/canvas-kit-react/collection'; +import {cornerShapeStencil, createSubcomponent} from '@workday/canvas-kit-react/common'; +import {CSProps, createStencil, handleCsProp, px2rem} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; + +import {useKBDModel} from './useKBDModel'; export interface KBDItemProps extends CSProps { /** @@ -12,16 +15,78 @@ export interface KBDItemProps extends CSProps { children?: React.ReactNode; } +export const kbdItemStencil = createStencil({ + extends: cornerShapeStencil, + base: { + [cornerShapeStencil.vars.shape]: system.legacy.shape.sm, + textAlign: 'center', + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + }, + modifiers: { + variant: { + plain: { + backgroundColor: system.legacy.color.surface.transparent, + borderRadius: 0, + cornerShape: 'unset', + }, + default: { + backgroundColor: system.sana.color.surface.alt.default, + }, + }, + }, + compound: [ + { + modifiers: { + size: 'large', + variant: 'default', + }, + styles: { + minWidth: system.legacy.size.xs, + padding: `${px2rem(2)} ${system.legacy.padding.xxs}`, + }, + }, + { + modifiers: { + size: 'medium', + variant: 'default', + }, + styles: { + minWidth: system.legacy.size.xxs, + padding: `${px2rem(2)} ${system.legacy.padding.xxs}`, + }, + }, + { + modifiers: { + size: 'small', + variant: 'default', + }, + styles: { + minWidth: system.legacy.size.xxxs, + paddingInline: px2rem(2), + }, + }, + ], +}); + /** - * `KBD.Item` renders a single keyboard key as a semantic `kbd` element. + * `KBD.Item` renders a single keyboard key as a semantic `kbd` element. It reads the `size` and + * `variant` from the {@link useKBDModel} provided by the parent `KBD` container. */ -export const KBDItem = createComponent('kbd')({ +export const KBDItem = createSubcomponent('kbd')({ displayName: 'KBD.Item', - Component: ({children, ...elemProps}: KBDItemProps, ref, Element) => { - return ( - - {children} - - ); - }, + modelHook: useKBDModel, + elemPropsHook: useListItemRegister, +})(({children, ...elemProps}, Element, model) => { + return ( + + {children} + + ); }); diff --git a/modules/labs-react/kbd/lib/useKBDModel.tsx b/modules/labs-react/kbd/lib/useKBDModel.tsx new file mode 100644 index 0000000000..60956ce442 --- /dev/null +++ b/modules/labs-react/kbd/lib/useKBDModel.tsx @@ -0,0 +1,56 @@ +import {useListModel} from '@workday/canvas-kit-react/collection'; +import {createModelHook} from '@workday/canvas-kit-react/common'; + +/** + * The `KBD` model extends the [Collection System](/get-started/for-developers/guides/collection-api/). + * It tracks the keyboard keys (`items`) and shares the `size` and `variant` of the keys with the + * `KBD.Item` subcomponents. + * + * ```tsx + * const model = useKBDModel({ + * size: 'large', + * variant: 'plain', + * items: ['⌘', 'C'], + * }); + * + * {item => {item}} + * ``` + */ +export const useKBDModel = createModelHook({ + defaultConfig: { + ...useListModel.defaultConfig, + /** + * The keyboard keys to render. Each string represents the label of a single key (e.g. `Ctrl`, + * `⌘`, `Enter`). When provided, use a render prop for the `KBD` children. + */ + items: [] as string[], + /** + * The size of the `KBD` keys. Shared with each `KBD.Item`. + * @default 'medium' + */ + size: 'medium' as 'small' | 'medium' | 'large', + /** + * The variant of the `KBD` keys. Shared with each `KBD.Item`. + * @default 'default' + */ + variant: 'default' as 'plain' | 'default', + }, + requiredConfig: useListModel.requiredConfig, + contextOverride: useListModel.Context, +})(config => { + const list = useListModel( + useListModel.mergeConfig(config, { + // `KBD` renders inline and has no scroll container, so virtualization would render no items + shouldVirtualize: false, + }) + ); + + return { + ...list, + state: { + ...list.state, + size: config.size, + variant: config.variant, + }, + }; +}); diff --git a/modules/labs-react/kbd/stories/KBD.mdx b/modules/labs-react/kbd/stories/KBD.mdx index 3c76072fa2..2bf6e9b05f 100644 --- a/modules/labs-react/kbd/stories/KBD.mdx +++ b/modules/labs-react/kbd/stories/KBD.mdx @@ -6,6 +6,7 @@ import {KBD} from '@workday/canvas-kit-labs-react/kbd'; import KBDStoriesMeta from './KBD.stories'; import {Basic} from './examples/Basic'; +import {Items} from './examples/Items'; import {RTL} from './examples/RTL'; import {Size} from './examples/Size'; import {Variant} from './examples/Variant'; @@ -31,14 +32,22 @@ yarn add @workday/canvas-kit-labs-react single keyboard key. > **Important:** When displaying a group of keyboard keys (such as Ctrl + C), -> **do not** combine them into a single `KBD.Item` (for example, `Ctrl + C`). -> Doing so will cause issues with RTL (right-to-left) positioning and keyboard shortcut display. -> -> Instead, wrap each key in its own `KBD.Item` and group them inside a `KBD` container. This ensures -> correct rendering and layout in both LTR and RTL environments. +> **do not** place that combination as a text into a single `KBD.Item` (for example, +> `Ctrl + C`). Doing so will cause issues with RTL (right-to-left) positioning +> and keyboard shortcut display. Instead, wrap each key in its own `KBD.Item` and group them inside +> a `KBD` container. This ensures correct rendering and layout in both LTR and RTL environments. +### Dynamic Items + +`KBD` is built on the [Collection API](/get-started/for-developers/guides/collection-api/). Instead +of rendering `KBD.Item` components statically, you can pass an array of strings to the `items` prop +and provide a render prop as the children. Each string represents the label of a single keyboard +key. + + + ### RTL Example You can also use the `KBD` component in right-to-left (RTL) layouts. This is helpful for languages @@ -49,17 +58,37 @@ that are read from right to left. ### Size The `KBD` component supports different sizes. You can adjust the size using the `size` prop with -options like `small`, `medium`, and `large` to suit various UI needs. +options like `small`, `medium`, and `large` to suit various UI needs. The `size` is shared with each +`KBD.Item` through the model. ### Variant The `KBD` component supports different variants through the `variant` prop. Use `default` for the -standard style or `plain` for a more minimal appearance. +standard style or `plain` for a more minimal appearance. The `variant` is shared with each +`KBD.Item` through the model. ## Component API + +## Model + +`KBD` uses a `useKBDModel` to track the keyboard keys (`items`) and to share the `size` and +`variant` with each `KBD.Item`. If you need direct access to the model's state, you can create it +yourself with `useKBDModel` and pass it to `KBD` via the `model` prop. + +```tsx +const model = useKBDModel({ + size: 'large', + variant: 'plain', + items: ['⌘', 'C'], +}); + +{item => {item}}; +``` + + diff --git a/modules/labs-react/kbd/stories/KBD.stories.tsx b/modules/labs-react/kbd/stories/KBD.stories.tsx index 9b6fa3ab2a..fb825e5b53 100644 --- a/modules/labs-react/kbd/stories/KBD.stories.tsx +++ b/modules/labs-react/kbd/stories/KBD.stories.tsx @@ -2,6 +2,7 @@ import {Meta} from '@storybook/react'; import mdxDoc from './KBD.mdx'; import {Basic as BasicExample} from './examples/Basic'; +import {Items as ItemsExample} from './examples/Items'; import {RTL as RTLExample} from './examples/RTL'; import {Size as SizeExample} from './examples/Size'; import {Variant as VariantExample} from './examples/Variant'; @@ -31,3 +32,7 @@ export const Size = { export const Variant = { render: VariantExample, }; + +export const Items = { + render: ItemsExample, +}; diff --git a/modules/labs-react/kbd/stories/examples/Basic.tsx b/modules/labs-react/kbd/stories/examples/Basic.tsx index 7ccd01b660..fade1dd170 100644 --- a/modules/labs-react/kbd/stories/examples/Basic.tsx +++ b/modules/labs-react/kbd/stories/examples/Basic.tsx @@ -28,6 +28,15 @@ export const Basic = () => { + P + + + + Shift + + + P + + +
); }; diff --git a/modules/labs-react/kbd/stories/examples/Items.tsx b/modules/labs-react/kbd/stories/examples/Items.tsx new file mode 100644 index 0000000000..c8bc009df2 --- /dev/null +++ b/modules/labs-react/kbd/stories/examples/Items.tsx @@ -0,0 +1,19 @@ +import {KBD} from '@workday/canvas-kit-labs-react/kbd'; +import {createStyles} from '@workday/canvas-kit-styling'; +import {system} from '@workday/canvas-tokens-web'; + +const containerStyles = createStyles({ + gap: system.gap.md, + display: 'flex', + flexDirection: 'column', +}); + +const items = ['⌘', 'Shift', 'P']; + +export const Items = () => { + return ( +
+ {item => {item}} +
+ ); +}; diff --git a/modules/labs-react/kbd/stories/examples/RTL.tsx b/modules/labs-react/kbd/stories/examples/RTL.tsx index fe5302fa71..46bf517a2c 100644 --- a/modules/labs-react/kbd/stories/examples/RTL.tsx +++ b/modules/labs-react/kbd/stories/examples/RTL.tsx @@ -23,6 +23,15 @@ export const RTL = () => { + P
+ + + + Shift + + + P + + + ); }; diff --git a/modules/labs-react/kbd/stories/visual-testing/testing.stories.tsx b/modules/labs-react/kbd/stories/visual-testing/testing.stories.tsx index cde0d7ffd2..405921746b 100644 --- a/modules/labs-react/kbd/stories/visual-testing/testing.stories.tsx +++ b/modules/labs-react/kbd/stories/visual-testing/testing.stories.tsx @@ -4,7 +4,7 @@ import { StaticStates, permutateProps, } from '@workday/canvas-kit-react/testing'; -import {createStyles} from '@workday/canvas-kit-styling'; +import {createStencil, createStyles} from '@workday/canvas-kit-styling'; import {system} from '@workday/canvas-tokens-web'; export default { @@ -17,11 +17,6 @@ export default { }, }; -const darkBackground = createStyles({ - background: system.color.surface.alt.default, - padding: system.padding.xs, -}); - export const KBDStates = () => ( ( {value: 'medium', label: 'Medium'}, {value: 'large', label: 'Large'}, ], + theme: [ + {value: undefined, label: ''}, + {value: 'sana-canvas', label: '(Sana Canvas)'}, + ], })} > - {props => ( -
+ {({dataTheme, ...props}) => ( +
C From d8beb81e17f000a00c3399035c73b1211e7b3f34 Mon Sep 17 00:00:00 2001 From: Raisa Primerova Date: Fri, 26 Jun 2026 09:51:03 -0600 Subject: [PATCH 06/10] docs: Add accessibility guidance --- modules/docs/mdx/16.0-UPGRADE-GUIDE.mdx | 9 ++-- modules/labs-react/kbd/stories/KBD.mdx | 41 +++++++++++++++++++ .../labs-react/kbd/stories/examples/Basic.tsx | 6 +-- 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/modules/docs/mdx/16.0-UPGRADE-GUIDE.mdx b/modules/docs/mdx/16.0-UPGRADE-GUIDE.mdx index b8b9eef266..4175284fc6 100644 --- a/modules/docs/mdx/16.0-UPGRADE-GUIDE.mdx +++ b/modules/docs/mdx/16.0-UPGRADE-GUIDE.mdx @@ -99,7 +99,7 @@ instructional prompts, or any UI patterns that reference specific keys. **Highlights:** -- Provides a semantic and accessible way to present keyboard keys and shortcuts to users. +- Provides a semantic (`kbd` element) way to visually present keyboard keys and shortcuts to users. - Supports various variants (`default` for prominence, `plain` for use on colored surfaces), as well as size options (`small`, `medium`, `large`). - Easy to use nested `KBD.Item` components for sequences or combinations. @@ -111,13 +111,14 @@ instructional prompts, or any UI patterns that reference specific keys. import {KBD} from '@workday/canvas-kit-labs-react'; - + C ; ``` -For more details and advanced usage, refer to the storybook documentation and our example stories -(e.g. for RTL, variants, and testing). +For more details and advanced usage, including accessibility guidance for symbolic keys and +functional shortcuts, refer to the storybook documentation and our example stories (e.g. for RTL, +variants, and testing). ## Component Updates diff --git a/modules/labs-react/kbd/stories/KBD.mdx b/modules/labs-react/kbd/stories/KBD.mdx index 2bf6e9b05f..9d2bd9552c 100644 --- a/modules/labs-react/kbd/stories/KBD.mdx +++ b/modules/labs-react/kbd/stories/KBD.mdx @@ -71,6 +71,47 @@ standard style or `plain` for a more minimal appearance. The `variant` is shared +## Accessibility + +`KBD` is **presentational and semantic text**. It renders a `kbd` element so assistive technology +can recognize the content as keyboard input, but it does **not** make a keyboard shortcut work or +expose it to the browser. It is the visual/semantic representation of a key, not the accessibility +contract for a functioning shortcut. + +### Provide spoken labels for symbolic or abbreviated keys + +Glyphs and abbreviations such as , , , and arrow keys are **not +announced reliably** across screen reader, browser, and OS combinations. When a `KBD.Item` contains +a symbol or abbreviation, add an `aria-label` with the spoken name of the key so it is announced +consistently: + +```tsx + + + C + +``` + +Plain alphanumeric keys (such as `C` above) read correctly on their own and don't need an +`aria-label`. + +### Expose the actual shortcut on the control it triggers + +`KBD` only documents a shortcut visually. If the shortcut is functional, also expose it on the +relevant interactive control using +[`aria-keyshortcuts`](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-keyshortcuts) +so assistive technology can communicate it to users: + +```tsx + +``` + ## Component API diff --git a/modules/labs-react/kbd/stories/examples/Basic.tsx b/modules/labs-react/kbd/stories/examples/Basic.tsx index fade1dd170..4b854243d9 100644 --- a/modules/labs-react/kbd/stories/examples/Basic.tsx +++ b/modules/labs-react/kbd/stories/examples/Basic.tsx @@ -20,15 +20,15 @@ export const Basic = () => { to pay respects. - + C - + Shift + P - + Shift From 1ea9d00573c251e06e406d38c6d1915fe79cfa64 Mon Sep 17 00:00:00 2001 From: Raisa Primerova Date: Fri, 26 Jun 2026 09:54:07 -0600 Subject: [PATCH 07/10] fix: Update testing to use sana-canvas theme by def --- .../kbd/stories/visual-testing/testing.stories.tsx | 8 ++------ modules/react/testing/lib/StaticStates.tsx | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/modules/labs-react/kbd/stories/visual-testing/testing.stories.tsx b/modules/labs-react/kbd/stories/visual-testing/testing.stories.tsx index 405921746b..9e5d4444c6 100644 --- a/modules/labs-react/kbd/stories/visual-testing/testing.stories.tsx +++ b/modules/labs-react/kbd/stories/visual-testing/testing.stories.tsx @@ -32,14 +32,10 @@ export const KBDStates = () => ( {value: 'medium', label: 'Medium'}, {value: 'large', label: 'Large'}, ], - theme: [ - {value: undefined, label: ''}, - {value: 'sana-canvas', label: '(Sana Canvas)'}, - ], })} > - {({dataTheme, ...props}) => ( -
+ {props => ( +
C diff --git a/modules/react/testing/lib/StaticStates.tsx b/modules/react/testing/lib/StaticStates.tsx index fb68664d56..c70820061c 100644 --- a/modules/react/testing/lib/StaticStates.tsx +++ b/modules/react/testing/lib/StaticStates.tsx @@ -43,7 +43,7 @@ export const StaticStates: React.FC< localTheme._styleRewriteFn = convertToStaticStates; return ( - + {children} ); From a5e9acc100a7cf3349c3276a0bb6bb8169ea55dc Mon Sep 17 00:00:00 2001 From: Raisa Primerova Date: Fri, 26 Jun 2026 10:09:14 -0600 Subject: [PATCH 08/10] fix: Fix type issue --- modules/react/testing/lib/StaticStates.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/react/testing/lib/StaticStates.tsx b/modules/react/testing/lib/StaticStates.tsx index c70820061c..c0d4bad604 100644 --- a/modules/react/testing/lib/StaticStates.tsx +++ b/modules/react/testing/lib/StaticStates.tsx @@ -43,7 +43,12 @@ export const StaticStates: React.FC< localTheme._styleRewriteFn = convertToStaticStates; return ( - + {children} ); From 199f6fb62eb4f13a7e1a533f7a18c04a629bb7f2 Mon Sep 17 00:00:00 2001 From: Raisa Primerova Date: Fri, 26 Jun 2026 10:58:05 -0600 Subject: [PATCH 09/10] fix: Add theme to inner part --- .storybook/preview.js | 2 +- modules/docs/lib/ExampleCodeBlock.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.storybook/preview.js b/.storybook/preview.js index cf8f64c4d0..74526fc3b0 100644 --- a/.storybook/preview.js +++ b/.storybook/preview.js @@ -20,7 +20,7 @@ export const globalTypes = { theme: { name: 'Theme', description: 'Token theme', - defaultValue: 'canvas', + defaultValue: 'sana', toolbar: { icon: 'paintbrush', items: [ diff --git a/modules/docs/lib/ExampleCodeBlock.tsx b/modules/docs/lib/ExampleCodeBlock.tsx index 9457840202..7346a26eb8 100644 --- a/modules/docs/lib/ExampleCodeBlock.tsx +++ b/modules/docs/lib/ExampleCodeBlock.tsx @@ -137,7 +137,7 @@ export const ExampleCodeBlock = ({code}: any) => { {/* This allows for the div to scroll on smaller viewports while not allowing the components to overflow over the container */} - + {React.createElement(code)} {code && (
From 99d70a17f343afb13c53b9a51ac402f77a9ea16a Mon Sep 17 00:00:00 2001 From: Raisa Primerova Date: Fri, 26 Jun 2026 11:08:21 -0600 Subject: [PATCH 10/10] fix: Update docs --- modules/docs/mdx/16.0-UPGRADE-GUIDE.mdx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/docs/mdx/16.0-UPGRADE-GUIDE.mdx b/modules/docs/mdx/16.0-UPGRADE-GUIDE.mdx index 4175284fc6..3e1e1db2aa 100644 --- a/modules/docs/mdx/16.0-UPGRADE-GUIDE.mdx +++ b/modules/docs/mdx/16.0-UPGRADE-GUIDE.mdx @@ -117,8 +117,7 @@ import {KBD} from '@workday/canvas-kit-labs-react'; ``` For more details and advanced usage, including accessibility guidance for symbolic keys and -functional shortcuts, refer to the storybook documentation and our example stories (e.g. for RTL, -variants, and testing). +functional shortcuts, refer to the storybook documentation and our example stories. ## Component Updates