Skip to content

Commit a832b0a

Browse files
authored
refactor(mantine): migrate QA tags response form to mantine DEV-1168 (#6390)
### 💭 Notes TLDR: Needed to create custom theme for mantine's `TagInput` as it has some hacky styling that is different than our defaults. Mantine's `TagInput` (and I suspect every other tag input library in some way) has a "input" that's actually a div, which wraps around an actual `<input>` element inside. This way it can display the tags in the same wrapper, before where the user would actually type the tags in. This means the default styles for mantine `<input>`'s can't apply here. The div wrapper "input" needs `focus-within` rather than `focus-visible`, as well as other default styles that we want to apply to its wrapper div instead. It's probably easier to understand by reading the code changes ### 👀 Preview steps 1. ℹ️ have an account and a project with NLP submissions 2. open NLP view 3. add a tags analysis question 5. 🟢 [on PR] notice that there is no functional differences between main
1 parent c045506 commit a832b0a

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

jsapp/js/components/processing/analysis/responseForms/tagsResponseForm.component.tsx

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { useContext, useState } from 'react'
22

3+
import { TagsInput } from '@mantine/core'
34
// We don't use `KoboTagsInput` here, because we don't want the tags splitting
45
// feature it has built in. It's easier for us to use `TagsInput` directly.
5-
import TagsInput from 'react-tagsinput'
66
import AnalysisQuestionsContext from '#/components/processing/analysis/analysisQuestions.context'
77
import {
88
findQuestion,
@@ -60,24 +60,7 @@ export default function TagsResponseForm(props: TagsResponseFormProps) {
6060
<CommonHeader uuid={props.uuid} />
6161

6262
<section className={commonStyles.content}>
63-
<TagsInput
64-
value={response}
65-
onChange={onTagsChange}
66-
// Adds a listener to changes on the internal text field before
67-
// text is added as a tag
68-
inputProps={{
69-
onChange: () => {
70-
analysisQuestions?.dispatch({ type: 'hasUnsavedWork' })
71-
},
72-
}}
73-
onlyUnique
74-
addOnBlur
75-
// We set this intentionally, because we don't want the pasted text
76-
// to be split, automatically transformed into tags, or already typed
77-
// in text to be lost after pasting.
78-
addOnPaste={false}
79-
disabled={!props.canEdit}
80-
/>
63+
<TagsInput value={response} onChange={onTagsChange} acceptValueOnBlur disabled={!props.canEdit} />
8164
</section>
8265
</>
8366
)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.pill {
2+
background-color: var(--mantine-color-gray-6);
3+
border-radius: var(--mantine-radius-sm);
4+
font-size: var(--mantine-font-size-md);
5+
color: var(--mantine-color-gray-1);
6+
}
7+
8+
.input:focus-within {
9+
box-shadow: 0 0 0 2px var(--mantine-color-blue-7);
10+
}
11+
12+
.input {
13+
border-color: var(--mantine-color-gray-6);
14+
15+
&::placeholder {
16+
color: var(--mantine-color-gray-3);
17+
opacity: 1;
18+
}
19+
}

jsapp/js/theme/kobo/TagsInput.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { TagsInput } from '@mantine/core'
2+
import classes from './TagsInput.module.css'
3+
4+
export const TagsInputThemeKobo = TagsInput.extend({
5+
classNames: classes,
6+
defaultProps: { size: 'md' },
7+
})

jsapp/js/theme/kobo/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { MenuThemeKobo } from './Menu'
99
import { ModalThemeKobo } from './Modal'
1010
import { SelectThemeKobo } from './Select'
1111
import { TableThemeKobo } from './Table'
12+
import { TagsInputThemeKobo } from './TagsInput'
1213
import { TooltipThemeKobo } from './Tooltip'
1314

1415
export const themeKobo = createTheme({
@@ -117,5 +118,6 @@ export const themeKobo = createTheme({
117118
Tooltip: TooltipThemeKobo,
118119
Table: TableThemeKobo,
119120
Divider: DividerThemeKobo,
121+
TagsInput: TagsInputThemeKobo,
120122
},
121123
})

0 commit comments

Comments
 (0)