Commit ae945afb authored by Lyza Danger Gardner's avatar Lyza Danger Gardner Committed by Lyza Gardner

Convert TagEditor to tailwind

Use shared `TextInput` component for presentational consistency.
parent 3f45b8c5
import { import {
normalizeKeyName, normalizeKeyName,
useElementShouldClose, useElementShouldClose,
TextInput,
} from '@hypothesis/frontend-shared'; } from '@hypothesis/frontend-shared';
import { useRef, useState } from 'preact/hooks'; import { useRef, useState } from 'preact/hooks';
...@@ -270,7 +271,7 @@ function TagEditor({ ...@@ -270,7 +271,7 @@ function TagEditor({
activeItem >= 0 ? `${tagEditorId}-AutocompleteList-item-${activeItem}` : ''; activeItem >= 0 ? `${tagEditorId}-AutocompleteList-item-${activeItem}` : '';
return ( return (
<div className="TagEditor space-y-4"> <div className="space-y-4">
<TagList> <TagList>
{tagList.map(tag => { {tagList.map(tag => {
return <TagListItem key={tag} onRemoveTag={onRemoveTag} tag={tag} />; return <TagListItem key={tag} onRemoveTag={onRemoveTag} tag={tag} />;
...@@ -278,7 +279,7 @@ function TagEditor({ ...@@ -278,7 +279,7 @@ function TagEditor({
</TagList> </TagList>
<div <div
id={tagEditorId} id={tagEditorId}
className="TagEditor__combobox-wrapper" data-testid="combobox-container"
ref={closeWrapperRef} ref={closeWrapperRef}
// Disabled because aria-controls must be attached to the <input> field // Disabled because aria-controls must be attached to the <input> field
// eslint-disable-next-line jsx-a11y/role-has-required-aria-props // eslint-disable-next-line jsx-a11y/role-has-required-aria-props
...@@ -287,13 +288,13 @@ function TagEditor({ ...@@ -287,13 +288,13 @@ function TagEditor({
aria-owns={`${tagEditorId}-AutocompleteList`} aria-owns={`${tagEditorId}-AutocompleteList`}
aria-haspopup="listbox" aria-haspopup="listbox"
> >
<input <TextInput
classes="w-full"
onInput={handleOnInput} onInput={handleOnInput}
onKeyDown={handleKeyDown} onKeyDown={handleKeyDown}
onFocus={handleFocus} onFocus={handleFocus}
ref={inputEl} inputRef={inputEl}
placeholder="Add new tags" placeholder="Add new tags"
className="TagEditor__input"
type="text" type="text"
autoComplete="off" autoComplete="off"
aria-autocomplete="list" aria-autocomplete="list"
......
...@@ -88,10 +88,8 @@ describe('TagEditor', () => { ...@@ -88,10 +88,8 @@ describe('TagEditor', () => {
it('adds appropriate tag values to the elements', () => { it('adds appropriate tag values to the elements', () => {
const wrapper = createComponent(); const wrapper = createComponent();
wrapper.find('li').forEach((tag, i) => { wrapper.find('TagListItem').forEach((tag, i) => {
assert.isTrue(tag.hasClass('TagEditor__item')); assert.equal(tag.props().tag, fakeTags[i]);
assert.include(tag.text(), fakeTags[i]);
assert.equal(tag.prop('aria-label'), `Tag: ${fakeTags[i]}`);
}); });
}); });
...@@ -455,6 +453,7 @@ describe('TagEditor', () => { ...@@ -455,6 +453,7 @@ describe('TagEditor', () => {
}); });
describe('accessibility attributes and ids', () => { describe('accessibility attributes and ids', () => {
const comboboxSelector = '[data-testid="combobox-container"]';
it('creates multiple <TagEditor> components with unique AutocompleteList `id` props', () => { it('creates multiple <TagEditor> components with unique AutocompleteList `id` props', () => {
const wrapper1 = createComponent(); const wrapper1 = createComponent();
const wrapper2 = createComponent(); const wrapper2 = createComponent();
...@@ -469,7 +468,7 @@ describe('TagEditor', () => { ...@@ -469,7 +468,7 @@ describe('TagEditor', () => {
wrapper.find('AutocompleteList'); wrapper.find('AutocompleteList');
assert.equal( assert.equal(
wrapper.find('.TagEditor__combobox-wrapper').prop('aria-owns'), wrapper.find(comboboxSelector).prop('aria-owns'),
wrapper.find('AutocompleteList').prop('id') wrapper.find('AutocompleteList').prop('id')
); );
}); });
...@@ -479,13 +478,13 @@ describe('TagEditor', () => { ...@@ -479,13 +478,13 @@ describe('TagEditor', () => {
wrapper.find('input').instance().value = 'non-empty'; // to open list wrapper.find('input').instance().value = 'non-empty'; // to open list
typeInput(wrapper); typeInput(wrapper);
assert.equal( assert.equal(
wrapper.find('.TagEditor__combobox-wrapper').prop('aria-expanded'), wrapper.find(comboboxSelector).prop('aria-expanded'),
'true' 'true'
); );
selectOption(wrapper, 'tag4'); selectOption(wrapper, 'tag4');
wrapper.update(); wrapper.update();
assert.equal( assert.equal(
wrapper.find('.TagEditor__combobox-wrapper').prop('aria-expanded'), wrapper.find(comboboxSelector).prop('aria-expanded'),
'false' 'false'
); );
}); });
......
@use '../../mixins/forms';
.TagEditor {
&__input {
@include forms.form-input;
width: 100%;
}
}
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
@use './SelectionTabs'; @use './SelectionTabs';
@use './SearchInput'; @use './SearchInput';
@use './StyledText'; @use './StyledText';
@use './TagEditor';
@use './Thread'; @use './Thread';
@use './ThreadCard'; @use './ThreadCard';
@use './ThreadList'; @use './ThreadList';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment