Skip to content
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

fix(components): replace reset icon on SearchInput component #555

Merged
merged 5 commits into from
Mar 27, 2020

Conversation

connor-baer
Copy link
Member

@connor-baer connor-baer commented Mar 24, 2020

Addresses #545.

Purpose

We have several problems with the SeachInput component:

  • it’s kinda broken on Safari (UI for SearchInput component is broken on Safari #545)
  • there is no clear icon in Firefox
  • when you click on the current default clear icon, there is no handler prop provided, so you clear the input value but you can’t do anything else when this happens

Approach and changes

  • Change the input type from "search" to "text"
  • Add a custom button to clear the input. When clicked, it calls the new onClear handler

👀 Preview

Definition of done

  • Development completed
  • Reviewers assigned
  • Unit and integration tests
  • Meets minimum browser support
  • Meets accessibility requirements

@codecov
Copy link

codecov bot commented Mar 24, 2020

Codecov Report

Merging #555 into canary will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           canary    #555      +/-   ##
=========================================
+ Coverage   79.68%   79.7%   +0.01%     
=========================================
  Files         173     173              
  Lines        2491    2493       +2     
  Branches      450     451       +1     
=========================================
+ Hits         1985    1987       +2     
  Misses        389     389              
  Partials      117     117
Impacted Files Coverage Δ
src/components/SearchInput/SearchInput.js 100% <100%> (ø) ⬆️

@vercel
Copy link

vercel bot commented Mar 24, 2020

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/sumup-oss/circuit-ui/ib9hdhb0j
✅ Preview: https://circuit-ui-git-feature-add-clear-to-search-input.sumup-oss.now.sh

Copy link
Member Author

@connor-baer connor-baer left a comment

Choose a reason for hiding this comment

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

✅ Approved once the tests pass (don't forget to update the storyshots).

(I can't approve the PR because I opened it myself 🙄)

src/components/SearchInput/SearchInput.js Outdated Show resolved Hide resolved
src/components/SearchInput/SearchInput.js Show resolved Hide resolved
@connor-baer connor-baer marked this pull request as ready for review March 25, 2020 16:20
@connor-baer
Copy link
Member Author

connor-baer commented Mar 26, 2020

I've been thinking about these changes — instead of adding a new onClear handler, how about we simply call the onChange handler with an empty string?

Consider this example:

// 1. With a separate onClear prop
const Search = () => {
  const [value, setValue] = useState("");

  const handleChange = event => {
    setValue(event.target.value);
  };

  const handleClear = () => {
    setValue('');
  }

  return <SearchInput value={value} onChange={handleChange} onClear={handleClear} />;
};

// 2. The clear button just calls `onChange('')`
const Search = () => {
  const [value, setValue] = useState('');

  const handleChange = (event) => {
    setValue(event.target.value);
  }

  return (
    <SearchInput value={value} onChange={handleChange} />
  );
}

The 2. example is more concise and more intuitive since the developer doesn't need to implement an additional handler. The clearing functionality would come "out of the box".

Thank you for considering these thoughts so late in the game. I think it's important that we get the component APIs in Circuit UI right.

Copy link
Contributor

@robinmetral robinmetral left a comment

Choose a reason for hiding this comment

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

👏

@marielakas
Copy link
Contributor

I've been thinking about these changes — instead of adding a new onClear handler, how about we simply call the onChange handler with an empty string?

Consider this example:

// 1. With a separate onClear prop
const Search = () => {
  const [value, setValue] = useState("");

  const handleChange = event => {
    setValue(event.target.value);
  };

  const handleClear = () => {
    setValue('');
  }

  return <SearchInput value={value} onChange={handleChange} onClear={handleClear} />;
};

// 2. The clear button just calls `onChange('')`
const Search = () => {
  const [value, setValue] = useState('');

  const handleChange = (event) => {
    setValue(event.target.value);
  }

  return (
    <SearchInput value={value} onChange={handleChange} />
  );
}

The 2. example is more concise and more intuitive since the developer doesn't need to implement an additional handler. The clearing functionality would come "out of the box".

Thank you for considering these thoughts so late in the game. I think it's important that we get the component APIs in Circuit UI right.

As discussed in Slack, I'm going to keep the current implementation. ;)

@marielakas marielakas merged commit bf3a8f9 into canary Mar 27, 2020
@marielakas marielakas deleted the feature/add-clear-to-search-input branch March 27, 2020 15:24
@ghost
Copy link

ghost commented Mar 27, 2020

🎉 This PR is included in version 1.7.1-canary.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ghost
Copy link

ghost commented Apr 29, 2020

🎉 This PR is included in version 1.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ghost ghost added the released label Apr 29, 2020
connor-baer added a commit that referenced this pull request Apr 30, 2020
* fix(components): prevent background from scrolling when modal is open (#531)

* fix(components): add class to html when Modal is open

Co-authored-by: Lari Maza <larissa.maza@sumup.com>

* fix(components): move global styles to ModalProvider

Co-authored-by: Lari Maza <larissa.maza@sumup.com>

Co-authored-by: Lari Maza <larissa.maza@gmail.com>

* fix(components): add top margin to Select below Label (#532)

* fix: adds Select margin top when label above

* fix: Adjust export naming for the base Select case

* Fix hamburger typos (#536)

* fix(components): remove scrollbar from LoadingButton (#542)

ISSUES CLOSED: #539

* chore(deploy): fix automatic deployment to GitHub Pages (#540)

* chore(configs): fix deployment to GH Pages

* chore(configs): resolve lint issues in Travis config

* chore(configs): do not run tests before deploy

* chore(configs): opt into v2 deployments

* chore(configs): deploy from the master branch only

* Revert "chore(configs): do not run tests before deploy"

This reverts commit 4d11c26.

* docs: fix Storybook links (#547)

* docs(docs): fix story hierarchy separators in links

* docs(components): prevent awkward wrapping on the homepage

* feat(components): add support for async filtering to AutoCompleteInput (#549)

* feat(components): add input value change callback to AutocompleteInput

This enables dynamic fetching and updating of the suggestion items.

* feat(components): add support for async filtering to the AutoCompleteInput

* docs(components): rename items to options

* test(components): update snapshots

* refactor(components): use new prop name in AutoCompleteTags

* feat(components): improve styles of AutocompleteInput

* style(components): rename style object

* fix(components): remove invalid Button props from HTML (#548)

* fix: don't pass invalid props to Link

* fix: added unit test

* fix: implemented shouldForwardProp

* fix(components): fill invalid radio button with red to match checkbox (#552)

* fix(components): replace reset icon on SearchInput component (#555)

* Remove default clear icon from SearchInput component

* Update snapshot tests

* Render clear icon based on onClear handler; Add unit tests

* Fix story

* Fix snapshot test

Co-authored-by: Mariela Kasovska <mariela.kasovska@sumup.com>

* docs: show addons panel by default (#557)

This should make it easier to find code samples.

* fix(components): make AutocompleteInput compatible with new clear option (#558)

* fix(components): make AutocompleteInput compatible with new clear option

* test(components): update storyshots

* fix(components): improve prop type

* feat(components): improve clear button on inputs (#559)

* feat(components): increase tap target size on input prefix and suffix

By switching from margin to padding for the spacing, the prefix and suffix elements get a much larger tap target size: 16px to 40px. This is especially important on touchscreen devices, but also improves usability for mouse users.

* feat(components): improve accessibility of the SearchInput clear button

* fix(components): deprecate showClear in favor of onClear prop

This brings the AutocompleteInput API in line with the SearchInput API. It also fixes the functionality of the clear button on the AutocompleteInput.

* fix(components): remove default prop to silence deprecation warning

* fix(components): add styles to the card elements in card stories

* feat(components): pass initial value to AutocompleteInput (#562)

* feat(components): pass initial value to AutocompleteInput

* test(components): update storyshots

* feat(components): refactor AutoCompleteTags (#561)

* Refactor AutoCompleteTags

* Update snapshot tests

* Make AutoCompleteTags class

* Update snapshots

* Update src/components/AutoCompleteTags/AutoCompleteTags.spec.js

Co-Authored-By: Connor Bär <connor-baer@users.noreply.github.com>

* Fix test

Co-authored-by: Connor Bär <connor-baer@users.noreply.github.com>

* fix(components): update clearfix to improve accessibility (#565)

* chore(configs): disable security script on Travis

This script errors most of the time. It works on the alpha branch which uses GitHub Actions.

* feat(components): update InfoIcon (#567)

* Update InfoIcon component

* feat(components): Toggle component - ability to be right aligned (#570)

* Toggle component - ability to be right aligned

* Fixed typo

* ESLint fix - max-len

* Storyshots snapshot updated

* PR comments changes

* Snapshot update

* Space added between text and Switch

* Snapshot update

* Reversed Toggle only shown on mobile

* feat(components): add optional suffix to the Tag component (#566)

* Replace right and left icon with render props

* Update docs and storyshots

* fix(components): reduce icon margin on Tag (#573)

* feat(components): remove deprecated props

alpha

* feat(configs): install @sumup/icons

feature/icons

* docs(docs): add page with icon search

feature/icons

* feat(components): remove CardSchemes and PaymentMethodIcon components

feature/icons

* feat(components): remove InfoIcon component

This component wasn't publicly exposed or used internally. Just dead code.

feature/icons

* feat(components): replace SVGs in CloseButton

feature/icons

* feat(components): rewrite Spinner in pure CSS

feature/icons

* feat(components): update LoadingButton with new Spinner

feature/icons

* feat(components): replace SVGs in Input components

feature/icons

* feat(components): replace SVG in Checkbox component

feature/icons

* feat(components): replace SVGs in Select component

feature/icons

* feat(components): replace SVGs in Notification component

feature/icons

* feat(components): replace SVGs in Calendar components

feature/icons

* feat(components): replace SVG in Table component

feature/icons

* feat(components): replace SVGs in Sidebar components

feature/icons

* WIP: replace SVGs in Carousel components

feature/icons

* test(components): update storyshots

feature/icons

* test(components): temporarily disable a11y test

feature/icons

* docs(docs): update icon color options

feature/icons

* feat(components): update icons to latest versions

feature/icons

* test(configs): fix typo in coverage config

feature/icons

* feat: update @sumup/icons to latest

feature/icons

* feat: update @sumup/icons to latest

feature/icons

Co-authored-by: Lari Maza <larissa.maza@gmail.com>
Co-authored-by: nico <nicosommi@gmail.com>
Co-authored-by: Lari Maza <larissa.maza@sumup.com>
Co-authored-by: Dmitri Suvorov <53574544+dmitri-suvorov-sumup@users.noreply.github.com>
Co-authored-by: Mariela Kasovska <mariela.kasovska@sumup.com>
Co-authored-by: Turcan Vladimir <36477870+justman00@users.noreply.github.com>
Co-authored-by: Hristian Garnev <62241171+hrstngrnvsmp@users.noreply.github.com>

BREAKING CHANGE:
The AutoCompleteInput's `defaultSelectedItem` prop has been renamed to `initialSelectedItem` to match Downshift's API.

BREAKING CHANGE:
The CardSchemes and PaymentMethodIcon components have been removed. Use
[@sumup/icons](https://github.com/sumup-oss/icons) instead.

BREAKING CHANGE:
The [@sumup/icons](https://github.com/sumup-oss/icons) package was added as a required peer dependency.
@github-actions
Copy link
Contributor

🎉 This PR is included in version 2.0.0-alpha.10 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants