-
Notifications
You must be signed in to change notification settings - Fork 1.4k
RSP-1129: Tag and TagGroup component #10
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
Conversation
|
Build successful! View the storybook |
|
Build successful! View the storybook |
|
Build successful! View the storybook |
|
Build successful! View the storybook |
|
Build successful! View the storybook |
snowystinger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CSS review
| .spectrum-Tags-item-ClearButton { | ||
| color: var(--spectrum-tag-border-color-error); | ||
| &.clearButton-focus { | ||
| color: white; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably be a var, i don't know which one though, @lazd can you review?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this line - new designs 🎈
| > .spectrum-Tags-item-ClearButton { | ||
| &.clearButton-focus { | ||
| background-color: var(--spectrum-tag-deletable-background-color-focus); | ||
| color: white; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use DNA tokens for these colors. Probably one of these:
--spectrum-tag-removable-icon-color: var(--spectrum-global-color-gray-600);
--spectrum-tag-removable-icon-color-hover: var(--spectrum-global-color-gray-900);
--spectrum-tag-removable-icon-color-down: var(--spectrum-global-color-gray-900);
--spectrum-tag-removable-icon-color-key-focus: var(--spectrum-global-color-gray-900);
--spectrum-tag-removable-icon-color-disabled: var(--spectrum-global-color-gray-500);
--spectrum-tag-removable-icon-color-error: var(--spectrum-global-color-red-500);
--spectrum-tag-removable-icon-color-error-hover: var(--spectrum-global-color-red-600);
--spectrum-tag-removable-icon-color-error-key-focus: var(--spectrum-global-color-red-600);
--spectrum-tag-removable-icon-color-error-down: var(--spectrum-global-color-red-700);
--spectrum-tag-removable-icon-color-error-disabled: var(--spectrum-global-color-gray-500);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If these tokens are out of date, please send a PR to Spectrum DNA: https://git.corp.adobe.com/Spectrum/spectrum-dna
| import {useTag} from '@react-aria/tag'; | ||
|
|
||
| export interface TagProps extends DOMProps { | ||
| children?: string | ReactNode, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does ReactElement cover this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it does 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unresolving until it's done
|
Few notes @snowystinger :
|
|
Build successful! View the storybook |
| let {result} = renderHook(() => useTag(props)); | ||
| expect(result.current.tagProps.onKeyDown).toBe(null); | ||
| expect(result.current.tagProps.tabIndex).toBe(-1); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will there be tests for the clearButtonProps as well or is that a later TODO?
|
Build successful! View the storybook |
|
Build successful! View the storybook |
| --spectrum-tag-border-color-error: rgb(236, 91, 98); | ||
| --spectrum-tag-icon-color-error: rgb(236, 91, 98); | ||
| --spectrum-tag-text-color-error: rgb(185, 185, 185); | ||
| --spectrum-tag-text-color-error: rgb(247, 109, 116); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'll need to contribute these variable changes to spectrum-dna at some point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. This is a generated file that will be overwritten. Do not edit it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is procedure?
Open pr in spectrum-dna and remove css changes from this PR and then this pr needs to wait spectrum-dna pr to be merged in order to have latest changes? Is it same if I need to add new variable? For example I used global var here https://github.com/adobe/react-spectrum-v3/pull/10/files#diff-aa7d70936a7ea3560aa2240e8e869fa5R106 and I suppose it should be --spectrum-tag-something, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can update/add the variables from your DNA PR in here temporarily, and we'll regenerate it later.
| onRemove, | ||
| children, | ||
| selected, | ||
| role |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we have a default role in case tag is used outside a tag group somehow?
|
Build successful! View the storybook |
7601b84 to
e9eabff
Compare
|
Build successful! View the storybook |
|
Build successful! View the storybook |
|
Build successful! View the storybook |
|
I will update css variables after https://git.corp.adobe.com/Spectrum/spectrum-dna/pull/338 is merged |
|
Build successful! View the storybook |
|
Build successful! View the storybook |
| </TagGroup> | ||
| ) | ||
| ).add( | ||
| 'with announcing', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to have announcing you need to navigate with keyboard into first tag and then you can press ctrl+d in order to create new tag. In that moment announcing should be triggered.
| id: buttonId, | ||
| title: removeString, | ||
| isDisabled, | ||
| role |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's weird to me that the labelProps and the clearButtonProps have the same role. I'd expect the role only to be on the tagProps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest I am new to accessibility and nothing makes sense, but here is the comment where Michael explains why #10 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Within a TagGroup, we are implementing the WAI-ARIA 1.1 Layout Grid design pattern: https://www.w3.org/TR/wai-aria-practices/examples/grid/LayoutGrids.html#ex2_label. The TagGroup container element has role="grid". Each Tag is a row within the grid with role="row". Each Tag contains one or, if the Tag can be removed, two cells. The label will have role="gridcell", and a wrapper span element around the clear button will also have role="gridcell".
| tagGroupProps: HTMLAttributes<HTMLElement> | ||
| } | ||
|
|
||
| export function useTagGroup(props: AriaTagGroupProps): TagGroupAria { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should useTagGroup have tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is returning plain object, there is noting to test. But if you feel it should have, I can add
| import {renderHook} from 'react-hooks-testing-library'; | ||
| import {useTag} from '../'; | ||
|
|
||
| describe('useTag tests', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should 'aria-selected' be tested too?
| role | ||
| } = useTagGroupProvider(); | ||
|
|
||
| let removable = isRemovable !== undefined ? isRemovable : isGroupRemovable; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn't the group property take precedence?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we should be flexible and allow user to override flags for child elements. I am not sure if there is a need for this, but it could be useful and it doesn't breaks anything. What do you think?
| import {useTag} from '@react-aria/tag'; | ||
| import {useTagGroupProvider} from './TagGroup'; | ||
|
|
||
| export const Tag = ((props: TagProps) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forwardRef?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to forward ref? And why?
| return useContext(TagGroupContext); | ||
| } | ||
|
|
||
| export const TagGroup = ((props: TagGroupProps) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forwardRef?
| import {Tag as V2Tag} from '@react/react-spectrum/TagList'; | ||
|
|
||
|
|
||
| describe('Tag', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are more tests planned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added more tests
| import React from 'react'; | ||
| import {Tag, TagGroup} from '../src'; | ||
|
|
||
| describe('TagGroup', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are more tests planned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added more tests
|
Build successful! View the storybook |
devongovett
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. You can do the following in a followup if you like.
| import {SyntheticEvent} from 'react'; | ||
|
|
||
| export interface Removable<T, R> { | ||
| isRemovable?: boolean, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm - this doesn't exist in the API spec for TagGroup. we have isReadOnly to mean this
| children?: ReactChild, | ||
| icon?: ReactElement, | ||
| isDisabled?: boolean, | ||
| isSelected?: boolean, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be a prop of Tag - should come from context. The selection state comes from MultipleSelectionBase on the group
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed flag, but now I don't know how to handle selection until I have multi selection hook. I removed stories for selected Tag and overall usage. If you agree, we can implement once we have actual selection state. Maybe as part of https://jira.corp.adobe.com/browse/RSP-1357?
* AriaTagProps moved to @react-aria/tag package * Deleted isRemovable flag and its usage from TagGroup * Removed isSelected flag and its usage for Tag (stories removed)
|
Build successful! View the storybook |
|
Build successful! View the storybook |
|
Build successful! View the storybook |
|
Build successful! View the storybook |

Closes
✅ Pull Request Checklist:
📝 Test Instructions:
🧢 Your Team: