Skip to content

feat: render the search input inside the dropdown #309

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

Merged
merged 44 commits into from
Jan 18, 2020

Conversation

ingmothman
Copy link
Contributor

@ingmothman ingmothman commented Nov 23, 2019

What does it do?

Allows us to show/hide the search input and change the location from the dropdown toggle to dropdown content.

Fixes #308

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • Updated documentation (if applicable)
  • Added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • My changes generate no new warnings

ellinge and others added 30 commits April 18, 2019 16:13
Adds TypeScript-definitions

I also noticed that onAction is not correctly implemented. Currently sends a { action: string, id: string }.
There is code in index.js which tries to fetch the node. But it does not seem be working. It expects two parameters but receives the object described above in the first parameter.
![bild](https://user-images.githubusercontent.com/17863113/54728331-8d972980-4b7d-11e9-9490-a3bd6b08481f.png)

Changed the examples/stories to get the node id at least.
Also changed in readme where onAction should be applied.

Fixes dowjones#209 

- [X] New feature
## What does it do?

An issue in dowjones#223 for children. An array of Node[] instead of TreeNode[] was specified.

## Type of change

- [x] Bug fix
## What does it do?

Prevents event bubbling on node expand-click. The function isOutsideClick only gets a short part of two items (li.node + i.expand), then the parents stop, in Firefox. This causes it to be detected as an outside click.

In chrome the path is instead empty and no outside click is therefore detected.

Fixes dowjones#198 

Can test here (switching between v1.17/developTemp):
Expand the first two nodes:
![bild](https://user-images.githubusercontent.com/17863113/55436725-5bce8b80-559d-11e9-927d-17149643100c.png)
Scroll to bottom and expand:
![bild](https://user-images.githubusercontent.com/17863113/55436759-6c7f0180-559d-11e9-8bd9-7ad141b5c9ca.png)

https://ellinge.github.io/react-dropdown-tree-select-test/#v117-nocheckeddefault
https://ellinge.github.io/react-dropdown-tree-select-test/#DevelopTemp-nocheckeddefault

There still seems to be some issue with scroll in firefox after initial scroll and expand which does not happen in chrome. The expanded item gets out of view. This also happens on scoll and check.

## Type of change

- [x] Bug fix
## What does it do?

Adds a "types (friendly) badge" to Readme

## Type of change

Please delete options that are not relevant.

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [X] This change requires a documentation update
## What does it do?

Adds prettierrc and pre commit hooks to format code automatically. Cleans up eslintrc and switched to react-app lint rules
## What does it do?

Adds support for single select in the tree dropdown. Simple select ignores any children so this is a hybrid between the two.

Also ignores clicks for simple select when labels are disabled (only checked readonly)

The middle dropdown is radioSelect and the last one a simpleSelect
https://ellinge.github.io/react-dropdown-tree-select-test/#DevelopTemp-checkeddefault

Fixes dowjones#119 

## Type of change
- [x] Bug fix
- [x] New feature
* feat: Test try a11y in test with axe

* fix: Initial commit (non working)

* fix: Working keyboard navigation

* fix: Backspace only on empty search

* fix: Adjust code to check codeclimate

* fix: Refactored some parts to utils

* fix: Refactored some parts to utils

* fix: Code refactoring

* fix: Add documentation

* fix: Refactor

* fix: Refactor

* fix: Refactor

* fix: Refactor

* fix: Refactor

* fix: Add to typings

* fix: Close on Enter

* fix: Refactor

* fix: Added test

* fix: Added some aria

* fix: Add label option

* fix: Render until node on pagedown

* fix: More tests added and fix pagedown on large search result

* fix: Modify output on violations

* fix: Code smells

* fix: Updated doc and center scrollIntoView, fix hasMore()

* fix: Trigger on*-events properly, only open for chars and whitelist

* fix: Skip som aria in this branch

* fix: Add tests and fix snapshot

* fix: Add tests and fix snapshot

* fix: Enabled by default

* fix: Avoid scroll of whole page, only dropdown

* fix: Remember focus during prop updates

* fix: Delete unintentional dist-file

* fix: Do not select readOnly/disabled

* fix: Switch to babel-plugin-transform-runtime instead

* fix: Add label to trigger as well

* fix: Highlight tag on focus, ad aria-labels

* fix: Highlight tag on focus, ad aria-labels

* fix: Update snapshots, match default

* fix: Allow navigate to disabled/readonly

* fix: Code review/smells fixes

* fix: Code smell

* fix: Code smell

* fix: Move to a11y-folder, shared onKeyDown test method

* fix: Build error and tabIndex

* fix: Set new focus after delete

* fix: Code climate

* fix: Code climate

* fix: Select on tab for simpleSelect

* fix: Add more tests

* fix: Add prop for setting remove aria-label

* fix: Code climate

* fix: Add typing for labelRemove

* fix: Adjust timeout

* style: Bring prettier manually to reduce conflicts

* fix: Prettier and removed comment

* fix: Added migration guide

* fix: Bundle text props

* fix: Typing errors

* fix: Renamed prop

* Revert "fix: Renamed prop"

This reverts commit 4145f8c.

* Revert "fix: Typing errors"

This reverts commit 6aa4beb.

* Revert "fix: Bundle text props"

This reverts commit 4256ce2.

* Revert "fix: Added migration guide"

This reverts commit a4fc033.

* fix: Validate radioSelect also

* fix: Moved around methods

* refactor: Separate out test utils from exported ones

* refactor: Use ES6 getter instead of custom method for accessing tags
* docs: update README.md

* docs: update .all-contributorsrc

(cherry picked from commit b5b803b)
* docs: update README.md

* docs: update .all-contributorsrc

(cherry picked from commit 095a329)
* fix: Remove babel-runtime from distribution bundle

babel-runtime is only needed for tests

* chore: Do not auto open stats everytime

(cherry picked from commit 071e7f5)
BREAKING CHANGE: Action Changes

- The option to pass a local `onAction` handler on a node is now removed. Use the **global** `onAction` event instead.

  ```jsx
  <DropdownTreeSelect onAction={onAction} ... />
  ```

- `onAction` signature is now consistent with signature for other event handlers such `onChange` and `onNodeToggle`

  ```js
  // before
  onAction = ({ action, id }) => {
    console.log(action, id)
  }

  // after
  onAction = (node, action) => {
    console.log(action, node.id)
  }
  ```

- Any custom props passed to `node` or `action` is accessible in the event properties. This will make it easier to add generic custom logic based on your custom data/properties which can be used instead of separate handlers.

  For example:

  ```js
  // node with action and custom props
  {
    id: 'mynode',
    propA: 'hello',
    propB: true,
    actions: [
      {
        id: 'myaction',
        propX: {...},
        propY: 12
      }
    ]
  }

  onAction = (node, action) => {
    console.log(node.propA, node.propB, action.propX, action.propY)
    // prints hello true {...} 12
  }

  ```
BREAKING CHANGE: Property changes

| Description                             | Usage before                                                | Usage after                                                   |
| --------------------------------------- | ----------------------------------------------------------- | ------------------------------------------------------------- |
| Added a new `mode` prop                 | `simpleSelect={true}` / `simpleSelect`                      | `mode='simpleSelect'`                                         |
| Bundled text props into a single object | `placeholderText='My text'`<br>`noMatchesText='No matches'` | `texts={{ placeholder: 'My text', noMatches: 'No matches' }}` |
BREAKING CHANGE: `hierarchical` prop

`hierarchical` prop is now moved under `mode` prop.

```
// before
<DropdownTreeSelect data={data} hierarchical={true} />

// after
<DropdownTreeSelect data={data} mode="hierarchical" />
```
BREAKING CHANGE: Property changes

| Description                             | Usage before                                                | Usage after                                                   |
| --------------------------------------- | ----------------------------------------------------------- | ------------------------------------------------------------- |
| Added a new `mode` prop                 | `simpleSelect={true}` / `simpleSelect`                      | `mode='simpleSelect'`                                         |
| Bundled text props into a single object | `placeholderText='My text'`<br>`noMatchesText='No matches'` | `texts={{ placeholder: 'My text', noMatches: 'No matches' }}` |
 - Avoids changing scroll if the current active descendant is the same for the tree (on prop updates on tree).
 - Also fixes jarring issue when selecting nodes on paging (index > 100/pagesize).
 - Partially fixes dowjones#257
Keeps dropdown open if updating with new props. Only updates/sets state open if new props cause the dropdown to show (a.k.a `initial`/`always`)

dowjones#253 introduced resetting of state for shopDropdown on new props:
New prop: `searchPredicate` - Adds support to filter nodes using custom search logic. For details, checkout README.
and ensure "Remove" label is read by Screen readers
@stale
Copy link

stale bot commented Dec 13, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Dec 13, 2019
@mrchief mrchief added wip Work In Progress and removed stale labels Dec 13, 2019
Copy link
Collaborator

@mrchief mrchief left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@osmancode Looks like I don't have push rights to this PR. I wanted to note a few things I found:

  • remove package-lock.json and update yarn.lock. This project uses yarn for dev, so we need to continue that.
  • the component width differs with inline search and no selections. I'm not sure if this is an issue or not. It seems like an artifact of how default browser styling happens and this is something one can fix using CSS, so I guess it's a non issue.
normal inline
image image

Everything else looks OK to me.

P.S.: A bit of trivia, I've added and removed Tags so many times in various experimental branches. Something always bothered me about it but I couldn't find enough justification to make it its own component without making it look like one, just for the sake of it. But now we have a solid justification!

<ul className={cx('tag-list')}>
{getTags(tags, onTagRemove, readOnly, disabled, texts.labelRemove)}
{children && <li className={cx('tag-item')}>{children}</li>}
{!children && (!tags || (tags && tags.length === 0)) && (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!tags || (tags && tags.length === 0)

Seems like a bit of excessive branching. Can we use ES6 defaults and eliminate branches or better yet, eliminate it altogether since it seems redundant.

{!children && (!tags || (tags && tags.length === 0)) && (
  <li className={cx('tag-item')}>
    <span className={cx('placeholder')}>{texts.placeholder || 'Choose...'}</span>
  </li>
)}

If no children, you'd render the placeholder regardless of tags or no tags, no?

I was wondering if we could do something like:

const lastItem = children || <span className={cx('placeholder')}>{texts.placeholder || 'Choose...'}</span>
return (
  <ul className={cx('tag-list')}>
    {getTags(tags, onTagRemove, readOnly, disabled, texts.labelRemove)}
    <li className={cx('tag-item')}>{lastItem}</li>
  </ul>
)

and maybe even inline getTags since there's no good reason for it to exist outside (it was done earlier to reduce code complexity when it was inside Input's render block).

Thoughts?

@ingmothman
Copy link
Contributor Author

@mrchief i have granted you push permissions over the my repo.

@mrchief
Copy link
Collaborator

mrchief commented Jan 8, 2020

@osmancode were you able to work on these changes?

@ingmothman
Copy link
Contributor Author

@mrchief i would like to but unfortunately i will be very busy for the next two months. do u think you will be able to finalize the PR?

@mrchief
Copy link
Collaborator

mrchief commented Jan 8, 2020

I'll try to... just didn't wanna duplicate efforts if you're already on it.

Gets rid of classnames dependency. This package was not being used for its main features anyway (just for emitting classnames conditionally).
@mrchief mrchief closed this Jan 18, 2020
@mrchief
Copy link
Collaborator

mrchief commented Jan 18, 2020

@osmancode I think stale bot closed this and if that's the case, I'd need to check its settings as it wasn't supposed to close wip PRs.

@mrchief mrchief reopened this Jan 18, 2020
# Conflicts:
#	README.md
#	__snapshots__/src/index.test.js.md
#	__snapshots__/src/index.test.js.snap
#	__snapshots__/src/input/index.test.js.snap
#	docs/src/stories/Options/index.js
#	package.json
#	src/index.js
#	src/index.test.js
#	src/input/index.js
#	src/tag/index.js
#	src/tree-node/index.js
#	src/tree-node/node-label.js
#	src/tree-node/toggle.js
#	src/trigger/index.js
#	types/react-dropdown-tree-select.d.ts
#	yarn.lock
Copy link

@codeclimate codeclimate bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR diff size of 25795 lines exceeds the maximum allowed for the inline comments feature.

@codeclimate
Copy link

codeclimate bot commented Jan 18, 2020

Code Climate has analyzed commit ef58bef and detected 2 issues on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 2

View more on Code Climate.

@mrchief mrchief changed the title feat: render the search input inside the dropdown. not on the toggle button feat: render the search input inside the dropdown Jan 18, 2020
@mrchief mrchief merged commit c5bfa8e into dowjones:develop Jan 18, 2020
@mrchief mrchief deleted the search-input-position branch January 18, 2020 23:38
@mrchief mrchief removed the wip Work In Progress label Jan 18, 2020
@mrchief
Copy link
Collaborator

mrchief commented Jan 18, 2020

🎉 This PR is included in version 2.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

m4theushw pushed a commit to m4theushw/react-dropdown-tree-select that referenced this pull request Sep 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

render the search input inside the dropdown. not on the toggle button
6 participants