Skip to content

Commit

Permalink
Dang-1761/search input no x when no text (#363)
Browse files Browse the repository at this point in the history
* do not show clear button if there is not a search term

* update package

* pr feedback changes

* update tests for searchBar

* remove outdated test

* update test to check for disabled
  • Loading branch information
shannamurry authored Nov 23, 2022
1 parent b99618b commit cd4d047
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# CHANGELOG

## v2.0.0-beta.7

### Features

Do not show clear button in `SearchBar` unless there is a search term

## v2.0.0-beta.6

### Features
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lob/ui-components",
"version": "2.0.0-beta.6",
"version": "2.0.0-beta.7",
"engines": {
"node": ">=14.18.2",
"npm": ">=8.3.0"
Expand Down
11 changes: 8 additions & 3 deletions src/components/SearchBar/SearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
</template>
<template #iconRight>
<button
class="block"
:class="[
'block',
searchTerm ? 'opacity-100 cursor-pointer' : 'opacity-0'
]"
:aria-label="t('search.closeLabel')"
:disabled="disabled"
data-testid="clearSearchButton"
Expand Down Expand Up @@ -150,8 +153,10 @@ export default {
});
},
clearSearch () {
this.searchTerm = '';
this.searchResults = [];
if (this.searchTerm) {
this.searchTerm = '';
this.searchResults = [];
}
},
onClickOutside ($event) {
if (this.$refs.searchBar) {
Expand Down
23 changes: 12 additions & 11 deletions src/components/SearchBar/__tests__/SearchBar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,6 @@ const renderComponent = (options) => render(SearchBar, { ...options, global: { m

describe('SearchBar', () => {

it('has the x button disabled when no text was entered', () => {
const props = {
...initialProps
};

const { queryByTestId } = renderComponent({ props });

const button = queryByTestId('clearSearchButton');
expect(button).toBeDisabled();
});

it('clears entered searchTerm when x button is clicked', async () => {
const searchTerm = 'something';
const props = {
Expand All @@ -68,6 +57,18 @@ describe('SearchBar', () => {
expect(input.value).toBe('');
});

it('does not show the clear button if there is no search term present', async () => {
const props = {
...initialProps
};

const { queryByTestId } = renderComponent({ props });

const button = queryByTestId('clearSearchButton');
expect(button).toHaveClass('opacity-0');
expect(button).toBeDisabled();
});

it('executes the search function when the user types', async () => {
const searchTerm = 'baseball';
const props = {
Expand Down

0 comments on commit cd4d047

Please sign in to comment.