Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Emotion] Convert euiFocusRing() mixin #5855

Merged
merged 10 commits into from
May 3, 2022
Merged

Conversation

cchaos
Copy link
Contributor

@cchaos cchaos commented Apr 29, 2022

My general thought process here is that we want to limit the variances in focus states across components, but we know that there are some places where we at least need to adjust the position (inset/outset) of the outline or better control the color. This is mainly a component driven and therefore, will can be adjusted through the new function.

At the global level, however, I can see a consumer (and eventually user) wanting to adjust some of the settings more broadly like making the outline thicker or making them all a specific color. These are the only tokens that can be adjusted.

Since we "pride" ourselves in accessibility, this pattern enforces consumers to use the standard outline property for focus rings and standardizes them across all components for consistency.

Global token

I've re-instated the top-level focus token on EuiTheme but reduced the original type to just color and width. I've left in the comments from the other keys for now as I'll revisit background colors and transparency later.

Screen Shot 2022-04-29 at 15 20 28 PM

Mixin -> Function

The new euiFocusRing()/useEuiFocusRing() function/hook returns a full css`` block of styles necessary to customize focus outlines with the ability to adjust color and `offset`.

Basic usage:

css`
  &:focus {
    ${useEuiFocusRing('outset', euiTheme.colors.primary)}
  }
`

You can also apply it un-scoped to :focus since outlines only apply to focus state anyway.

image

Global reset

The reset file has been updated to use the function directly so that we're only creating these styles once. It also fixed the current offset in the reset which was not get calculated correctly. The following screenshot compares the style output based on the 3 usages (none, without :focus, with :focus):

image

Checklist

  • Checked in both light and dark modes
  • [ ] Checked in mobile
  • Checked in Chrome, Safari, Edge, and Firefox
  • Props have proper autodocs and playground toggles
  • Added documentation
  • [ ] Checked Code Sandbox works for any docs examples
  • Added or updated jest and cypress tests
  • [ ] Checked for breaking changes and labeled appropriately
  • Checked for accessibility including keyboard-only and screenreader modes
  • [ ] Updated the Figma library counterpart
  • A changelog entry exists and is marked appropriately

{finalSnippet && (
<EuiCodeBlock
whiteSpace="pre"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm now forcing these snippets to scroll horizontally because the wrapping causes weird line-breaks making it hard to read.

@@ -58,6 +59,7 @@ export const ThemeValue: FunctionComponent<ThemeValue> = ({
numberProps,
stringProps,
colorProps,
forceUpdateType,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The theme value customizing component now accepts a forced type for rendering the update form component. For instance, the type for focus.color is your typical ColorModeSwitch but we're just setting it to a simple string currentColor so I'm forcing the updating form element to render a text input instead of the color picker.

Comment on lines +14 to +15
&.euiSplitPanel-isResponsive.euiPanel--#{$modifier} > .euiSplitPanel__inner,
&.euiPanel--#{$modifier} > .euiSplitPanel__inner {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside fix:

I needed to fix the scope of the border radius' for nested split panels.

// 👉 Safari and Firefox innately respect only showing the outline with keyboard only
// 💔 But they don't allow coloring of the 'auto'/default outline, so contrast is no good in dark mode.
// 👉 For these browsers we use the solid type in order to match with \`currentColor\`.
// 😦 Which does means the outline will be square
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these comments moved to the function.

@@ -11,7 +11,7 @@ import { CSSProperties } from 'react';

/**
* NOTE: These were quick conversions of their Sass counterparts.
* They have yet to be used/tested.
* The commented out keys have not been established as necessary yet.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping unused but already "converted" values in these files til I can get to them.

* This re-applies the same default outline with a couple parameters
* @param euiTheme UseEuiTheme.euiTheme
* @param offset Accepts a specific measurement or 'inset' or 'outset' or 'center' to adjust outline position
* @param color Accepts any CSS color, **Note: only works in -webkit-**
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to reviewers too: Firefox does not support the color parameter on outline.

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5855/

Copy link
Contributor

@miukimiu miukimiu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @cchaos. Tested locally in Chrome, Firefox, and Safari. LGTM! 🎉

src/global_styling/variables/states.ts Outdated Show resolved Hide resolved
Comment on lines +57 to +63
<p>
By default, all interactable elements will inherit the{' '}
<EuiCode>outline</EuiCode> property from the reset file. However,
some instances require adjustment to the <EuiCode>offset</EuiCode>{' '}
and <EuiCode>color</EuiCode> of this outline. This helper function
allows that customization of the focus outline.
</p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should list what are the available offset options: 'inset' | 'outset' | 'center' | CSSProperties['outlineOffset']. I'm just thinking what if I'm using this hook without TS?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it starts getting into the territory of having to duplicate prop types. I wonder if there's a way we can do this programmatically instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and added this one in manually, making space for it in the re-used component ThemeExample. I'm hoping someone smarter than me will be able to create a re-usable service 😸

Co-authored-by: Elizabet Oliveira <elizabet.oliveira@elastic.co>
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5855/

@cchaos cchaos requested a review from thompsongl May 2, 2022 19:52
@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5855/

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_5855/

Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes LGTM!

@cchaos cchaos merged commit 89c0d55 into elastic:main May 3, 2022
@cchaos cchaos deleted the css-in-js/focus branch May 3, 2022 15:43
cchaos pushed a commit to cchaos/eui that referenced this pull request May 3, 2022
* Commented out some unused (yet) properties and updated the Focus docs section
* Make `focus` global token required
* Updated ThemeExamples code snippets to scroll horizontally

* [EuiSplitPanel] Fix border-radius of nested split panels
# Conflicts:
#	src/global_styling/mixins/index.ts
@miukimiu miukimiu mentioned this pull request May 4, 2022
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants