Skip to content

Commit

Permalink
fix(picker): rename is-focused to is-keyboardFocused
Browse files Browse the repository at this point in the history
Rather than removing the class, keep it in its renamed form in order
for SWC to still be able to convert it to an attribute and continue
testing it via its Storybook control.
  • Loading branch information
jawinn authored and castastrophe committed Jan 17, 2024
1 parent b2a40e9 commit 5a5925b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
12 changes: 8 additions & 4 deletions components/picker/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ governing permissions and limitations under the License.
--highcontrast-picker-content-color-disabled: GrayText;
--highcontrast-picker-background-color: ButtonFace;

&:focus-visible {
&:focus-visible,
&.is-keyboardFocused {
--highcontrast-picker-border-color-hover: ButtonText;
}

Expand Down Expand Up @@ -263,7 +264,8 @@ governing permissions and limitations under the License.
}
}

&:focus-visible {
&:focus-visible,
&.is-keyboardFocused {
outline: none;
background-color: var(--highcontrast-picker-background-color, var(--mod-picker-background-color-key-focus, var(--spectrum-picker-background-color-key-focus)));
border-color: var(--highcontrast-picker-border-color-default, var(--mod-picker-border-color-key-focus, var(--spectrum-picker-border-color-key-focus)));
Expand Down Expand Up @@ -306,7 +308,8 @@ governing permissions and limitations under the License.
border-color: var(--highcontrast-picker-border-color-hover, var(--mod-picker-border-color-error-hover-open, var(--spectrum-picker-border-color-error-hover-open)));
}

&:focus-visible {
&:focus-visible,
&.is-keyboardFocused {
border-color: var(--highcontrast-picker-border-color-default, var(--mod-picker-border-color-error-key-focus, var(--spectrum-picker-border-color-error-key-focus)));
}
}
Expand Down Expand Up @@ -463,7 +466,8 @@ governing permissions and limitations under the License.
background-color: var(--highcontrast-picker-background-color, transparent);
}

&:focus-visible {
&:focus-visible,
&.is-keyboardFocused {
background-color: var(--highcontrast-picker-background-color, transparent);

/* Focus indicator changes from a ring to a line underneath. */
Expand Down
16 changes: 11 additions & 5 deletions components/picker/stories/picker.stories.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Default as MenuStories } from "@spectrum-css/menu/stories/menu.stories.js";
import { within } from "@storybook/testing-library";
import { Template } from "./template";

export default {
Expand Down Expand Up @@ -63,6 +62,15 @@ export default {
},
control: "boolean",
},
isKeyboardFocused: {
name: "Keyboard focused",
type: { name: "boolean" },
table: {
type: { summary: "boolean" },
category: "State",
},
control: "boolean",
},
isDisabled: {
name: "Disabled",
type: { name: "boolean" },
Expand Down Expand Up @@ -98,6 +106,7 @@ export default {
label: "Country",
placeholder: "Select a country",
isQuiet: false,
isKeyboardFocused: false,
isLoading: false,
isDisabled: false,
isInvalid: false,
Expand Down Expand Up @@ -168,14 +177,11 @@ export const Focused = Template.bind({});
Focused.storyName = "Keyboard Focused";
Focused.args = {
helpText: "Please select a country",
isKeyboardFocused: true,
content: [
() => MenuStories(MenuStories.args)
],
};
Focused.play = async ({ canvasElement }) => {
const canvas = within(canvasElement);
await canvas.getByRole("button").focus();
};

export const WithForcedColors = Template.bind({
parameters: {
Expand Down
5 changes: 5 additions & 0 deletions components/picker/stories/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const Picker = ({
labelPosition,
placeholder,
isQuiet = false,
isKeyboardFocused = false,
isOpen = false,
isInvalid = false,
isLoading = false,
Expand Down Expand Up @@ -51,6 +52,7 @@ export const Picker = ({
[`is-invalid`]: isInvalid,
[`is-open`]: isOpen,
[`is-loading`]: isLoading,
[`is-keyboardFocused`]: isKeyboardFocused,
...customClasses.reduce((a, c) => ({ ...a, [c]: true }), {}),
})}
?disabled=${isDisabled}
Expand Down Expand Up @@ -94,6 +96,7 @@ export const Template = ({
placeholder,
helpText,
isQuiet = false,
isKeyboardFocused = false,
isOpen = false,
isInvalid = false,
isLoading = false,
Expand Down Expand Up @@ -148,6 +151,7 @@ export const Template = ({
size,
placeholder,
isQuiet,
isKeyboardFocused,
isOpen,
isInvalid,
isLoading,
Expand All @@ -169,6 +173,7 @@ export const Template = ({
size,
placeholder,
isQuiet,
isKeyboardFocused,
isOpen,
isInvalid,
isLoading,
Expand Down

0 comments on commit 5a5925b

Please sign in to comment.