diff options
author | Dessalines <dessalines@users.noreply.github.com> | 2020-07-10 14:01:45 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-10 14:01:45 -0400 |
commit | 8e96507cb19f7694a31a1407d1bcd2a347a70342 (patch) | |
tree | e5bcc0c14c3a8109bb85e5536b557497fa55287f /ui/src | |
parent | debbd316c271f8867917a9eb8c4caa5c26093d66 (diff) |
Replacing selectr with choices.js for community searching. (#932)
- Fixes #839
- Fixes #847
Diffstat (limited to 'ui/src')
-rw-r--r-- | ui/src/components/post-form.tsx | 46 | ||||
-rw-r--r-- | ui/src/index.html | 2 |
2 files changed, 42 insertions, 6 deletions
diff --git a/ui/src/components/post-form.tsx b/ui/src/components/post-form.tsx index fc7884d7..247c4cc6 100644 --- a/ui/src/components/post-form.tsx +++ b/ui/src/components/post-form.tsx @@ -39,7 +39,7 @@ import { import autosize from 'autosize'; import Tribute from 'tributejs/src/Tribute.js'; import emojiShortName from 'emoji-short-name'; -import Selectr from 'mobius1-selectr'; +import Choices from 'choices.js'; import { i18n } from '../i18next'; const MAX_POST_TITLE_LENGTH = 200; @@ -69,6 +69,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> { private id = `post-form-${randomStr()}`; private tribute: Tribute; private subscription: Subscription; + private choices: Choices; private emptyState: PostFormState = { postForm: { name: null, @@ -164,6 +165,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> { componentWillUnmount() { this.subscription.unsubscribe(); + this.choices.destroy(); window.onbeforeunload = null; } @@ -596,11 +598,45 @@ export class PostForm extends Component<PostFormProps, PostFormState> { // Set up select searching let selectId: any = document.getElementById('post-community'); if (selectId) { - let selector = new Selectr(selectId, { nativeDropdown: false }); - selector.on('selectr.select', option => { - this.state.postForm.community_id = Number(option.value); - this.setState(this.state); + this.choices = new Choices(selectId, { + shouldSort: false, + classNames: { + containerOuter: 'choices', + containerInner: 'choices__inner bg-secondary border-0', + input: 'form-control', + inputCloned: 'choices__input--cloned', + list: 'choices__list', + listItems: 'choices__list--multiple', + listSingle: 'choices__list--single', + listDropdown: 'choices__list--dropdown', + item: 'choices__item bg-secondary', + itemSelectable: 'choices__item--selectable', + itemDisabled: 'choices__item--disabled', + itemChoice: 'choices__item--choice', + placeholder: 'choices__placeholder', + group: 'choices__group', + groupHeading: 'choices__heading', + button: 'choices__button', + activeState: 'is-active', + focusState: 'is-focused', + openState: 'is-open', + disabledState: 'is-disabled', + highlightedState: 'text-info', + selectedState: 'text-info', + flippedState: 'is-flipped', + loadingState: 'is-loading', + noResults: 'has-no-results', + noChoices: 'has-no-choices', + }, }); + this.choices.passedElement.element.addEventListener( + 'choice', + (e: any) => { + this.state.postForm.community_id = Number(e.detail.choice.value); + this.setState(this.state); + }, + false + ); } } else if (res.op == UserOperation.CreatePost) { let data = res.data as PostResponse; diff --git a/ui/src/index.html b/ui/src/index.html index 07d188e2..097ad34b 100644 --- a/ui/src/index.html +++ b/ui/src/index.html @@ -13,7 +13,7 @@ <!-- Styles --> <link rel="stylesheet" type="text/css" href="/static/assets/css/tribute.css" /> <link rel="stylesheet" type="text/css" href="/static/assets/css/toastify.css" /> - <link rel="stylesheet" type="text/css" href="/static/assets/css/selectr.min.css" /> + <link rel="stylesheet" type="text/css" href="/static/assets/css/choices.min.css" /> <link rel="stylesheet" type="text/css" href="/static/assets/css/tippy.css" /> <link rel="stylesheet" type="text/css" href="/static/assets/css/themes/litely.min.css" id="default-light" media="(prefers-color-scheme: light)" /> <link rel="stylesheet" type="text/css" href="/static/assets/css/themes/darkly.min.css" id="default-dark" media="(prefers-color-scheme: no-preference), (prefers-color-scheme: dark)" /> |