From 34aac9004a07dbd90f6bfb736f0dfa9c28bf26d2 Mon Sep 17 00:00:00 2001 From: Josh Winn <965114+jawinn@users.noreply.github.com> Date: Wed, 30 Oct 2024 13:29:19 -0400 Subject: [PATCH] docs: fix and document use of keyboard focus classes on text fields Our Storybook was adding the keyboard focus class on click, which isn't the intended design. Click focus and focused by use of a keyboard have different styles. This update stops the class from being applied on click, and documents how the class should be added by the implementation. --- components/textfield/stories/template.js | 34 ++++++++++++++++--- .../textfield/stories/textarea.stories.js | 30 ++++++++++------ .../textfield/stories/textarea.template.js | 28 ++++++++++++++- .../textfield/stories/textfield.stories.js | 30 +++++++++++----- 4 files changed, 97 insertions(+), 25 deletions(-) diff --git a/components/textfield/stories/template.js b/components/textfield/stories/template.js index 9a7f064cd3..72ba6d0d82 100644 --- a/components/textfield/stories/template.js +++ b/components/textfield/stories/template.js @@ -120,15 +120,13 @@ export const Template = ({ style=${styleMap(customStyles)} @click=${onclick} @focusin=${function() { - updateArgs({ + updateArgs?.({ isFocused: true, - isKeyboardFocused: true }); }} @focusout=${function() { - updateArgs({ + updateArgs?.({ isFocused: false, - isKeyboardFocused: false }); }} id=${ifDefined(id)} @@ -231,7 +229,7 @@ export const TextFieldOptions = (args, context) => Container({ "gap": "8px", }, heading: "Default", - content: Template({...args, context}) + content: Template(args, context) })} ${Container({ withBorder: false, @@ -275,3 +273,29 @@ export const TextFieldOptions = (args, context) => Container({ })} ` }); + +export const KeyboardFocusTemplate = (args, context) => Container({ + direction: "column", + withBorder: false, + wrapperStyles: { + rowGap: "12px", + }, + content: html` + ${Container({ + withBorder: false, + containerStyles: { + "gap": "8px", + }, + heading: "Default", + content: Template({...args, isKeyboardFocused: true}, context) + })} + ${Container({ + withBorder: false, + containerStyles: { + "gap": "8px", + }, + heading: "Quiet", + content: Template({...args, isKeyboardFocused: true, isQuiet: true}, context) + })} + ` +}); diff --git a/components/textfield/stories/textarea.stories.js b/components/textfield/stories/textarea.stories.js index f91dc576ee..a7571aa3d1 100644 --- a/components/textfield/stories/textarea.stories.js +++ b/components/textfield/stories/textarea.stories.js @@ -2,14 +2,13 @@ import { Sizes } from "@spectrum-css/preview/decorators"; import { disableDefaultModes } from "@spectrum-css/preview/modes"; import metadata from "../metadata/metadata.json"; import packageJson from "../package.json"; -import { HelpTextOptionsTextArea, Template, TextAreaOptions } from "./textarea.template.js"; +import { HelpTextOptionsTextArea, KeyboardFocusTemplate, Template, TextAreaOptions } from "./textarea.template.js"; import { TextAreaGroup } from "./textarea.test.js"; import { default as Textfield } from "./textfield.stories.js"; /** * A text area is multi-line text field using the `