-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add interaction stories for buttons, number field, and anchor (#1919)
## π€¨ Rationale Part of #495 ## π©βπ» Implementation I had to make some changes in `storybook-addon-pseudo-states` to support our styling, but now we can pull in that fixed release and add some initial visual tests. The way the addon typically works is that you set story parameters to select which component(s) should have the pseudo-state styling, e.g. ```js ButtonStory.parameters = { pseudo: { hover: ["#one", "#two", "#three"], focus: true, // means apply to all components active: ".some-class", }, } ``` However, this does work well with our matrix story approach. The effect of these parameters is just to set certain classes on the indicated elements. So, instead, we can bypass the story parameters and directly apply the classes to our elements. For example, any element with the class `hover` or `pseudo-hover-all` will be styled by the addon as if hovered. NOTE: Because we have to put the classes directly on the elements in our Story html, we can't put them on any shadow DOM elements, e.g. the inc/dec buttons of the number field. However, puting `pseudo-<state>-all` on a host element will cause all elements in its shadow DOM to be styled as if they have that state. This can create some visuals that are practically impossible (e.g. a number field and both of its inc/dec buttons all having keyboard focus at the same time), but they are still useful from a visual testing standpoint. The pseudo-states supported by the addon are: - `:hover` - `:active` - `:focus-visible` - `:focus-within` - `:focus` - `:visited` - `:link` - `:target` It is only interesting to test states that we specifically style for, so generally, that is hover, active, and some form of focused. Because our components use both `:focus-visible` (`focusVisible` from FAST) and `:focus-within`, I'm not distinguishing the two, and I'm setting classes for both whenever we want to see "focused" styling. We could potentially test all combinations of these pseudo-states, but that seems unnecessary, especially considering that we want to test these states in _conjunction_ with other appearance/config variations. So I'm limiting combination testing to just hovered+active, since that is a common use case for mouse-based interaction. To summarize, that means I'm proposing we test: - hover (only) - active (only) - focused (only) - hovered and active Initially, I'm adding new test matrix stories for: - anchor - anchor-button - button - menu-button - number-field - toggle-button These seemed to be some of the more interesting components in terms of having distinct keyboard-focused and/or active states, (in addition to hover, which applies to most/all? components). Some combinations of interaction states with control attribute values aren't interesting, e.g. a disabled control with focus or active interaction state. In order to exclude certain combinations, we had to refactor the `createMatrix` utility function and introduce a new `createMatrixInteractionsFromStates` function. ## π§ͺ Testing Storybook visual tests ## β Checklist - [x] I have updated the project documentation to reflect my changes or determined no changes are needed. --------- Co-authored-by: rajsite <rajsite@users.noreply.github.com>
- Loading branch information
Showing
14 changed files
with
330 additions
and
213 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@ni-nimble-components-ceebd404-0fb3-43e5-8f98-04f4eed64531.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "none", | ||
"comment": "Add interaction stories for buttons, number field, and anchor", | ||
"packageName": "@ni/nimble-components", | ||
"email": "7282195+m-akinc@users.noreply.github.com", | ||
"dependentChangeType": "none" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,5 +15,8 @@ addons.setConfig({ | |
} | ||
} | ||
}, | ||
theme | ||
theme, | ||
toolbar: { | ||
'storybook/pseudo-states/tool': { hidden: true } | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.