Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.

Commit cb406f9

Browse files
committed
feat: UiFilter reset button only shows when there is something to reset
1 parent 563de37 commit cb406f9

File tree

5 files changed

+74
-16
lines changed

5 files changed

+74
-16
lines changed

addon/components/ui-filter/input/component.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { className, layout } from '@ember-decorators/component';
1+
import { className, classNames, layout } from '@ember-decorators/component';
22
import { action } from '@ember/object';
33
import { empty, or } from '@ember/object/computed';
44
import Component from '@ember/component';
@@ -7,6 +7,7 @@ import template from './template';
77
/**
88
* The UiFilterInput component
99
*/
10+
@classNames('ui-filter ui-filter-input')
1011
@layout(template)
1112
export default class UiFilterInput extends Component {
1213
/**
@@ -29,6 +30,11 @@ export default class UiFilterInput extends Component {
2930
*/
3031
public showClearButton = false;
3132

33+
/**
34+
* The name of the icon to use with the close button.
35+
*/
36+
public clearButtonIcon = 'times';
37+
3238
/**
3339
* An array that will be used to populate a menu of options that can
3440
* be selected to auto-populate the text input.

addon/components/ui-filter/input/template.hbs

+10-11
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,16 @@
2525
oninput={{this.handleInputChange}}
2626
>
2727

28-
{{#if this.showClearButton}}
29-
<span class="input-group-btn">
30-
<UiButton
31-
@variant="{{if this.showErrorMessage "danger" "default"}}"
32-
@ariaLabel="{{concat "Reset " this.label}}"
33-
@title="{{concat "Reset " this.label}}"
34-
@disabled={{or this.disabled this.noValue}}
35-
@onClick={{this.handleInputReset}}
36-
@icon="times"
37-
/>
38-
</span>
28+
{{#if (and this.showClearButton this.value)}}
29+
<UiButton
30+
@variant="{{if this.showErrorMessage "danger" "default"}}"
31+
@ariaLabel="{{concat "Reset " this.label}}"
32+
@title="{{concat "Reset " this.label}}"
33+
@disabled={{or this.disabled this.noValue}}
34+
@onClick={{this.handleInputReset}}
35+
@icon="{{this.clearButtonIcon}}"
36+
class="ui-filter-reset"
37+
/>
3938
{{/if}}
4039

4140
<UiTooltipAttachment

app/styles/_ui-foundation.scss

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
@forward "ui-foundation/components/button-column" as button-column-*;
88
@forward "ui-foundation/components/progress-chevron" as progress-chevron-*;
99
@forward "ui-foundation/components/table" as table-*;
10+
@forward "ui-foundation/components/filter" as filter-*;
1011
@forward "ui-foundation/utilities/responsive" as responsive-utilities-*;
1112
@forward "ui-foundation/utilities/spacing" as spacing-utilities-*;
1213

@@ -21,11 +22,13 @@
2122
@use "ui-foundation/components/button-column";
2223
@use "ui-foundation/components/progress-chevron";
2324
@use "ui-foundation/components/table";
25+
@use "ui-foundation/components/filter";
2426

2527
@mixin style() {
2628
@include button-column.style();
2729
@include progress-chevron.style();
2830
@include table.style();
31+
@include filter.style();
2932

3033
@include responsive.style();
3134
@include spacing.style();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
@use "../functions/logic";
2+
3+
$-input-border-radius: 4px;
4+
$-input-background-color: #fff;
5+
$-input-danger-color: #d9534f;
6+
7+
/**
8+
* Configuration for the UiFilter module.
9+
*/
10+
@mixin configure(
11+
$input-border-radius: null,
12+
$input-background-color: null,
13+
$input-danger-color: null,
14+
) {
15+
$-input-border-radius: logic.truthy($input-border-radius, $-input-border-radius) !global;
16+
$-input-background-color: logic.truthy($input-background-color, $-input-background-color) !global;
17+
$-input-danger-color: logic.truthy($input-danger-color, $-input-danger-color) !global;
18+
}
19+
20+
/**
21+
* UiFilter Styling.
22+
*/
23+
@mixin style() {
24+
.ui-filter {
25+
&.ui-filter-input {
26+
position: relative;
27+
28+
input {
29+
border-top-right-radius: $-input-border-radius !important;
30+
border-bottom-right-radius: $-input-border-radius !important;
31+
}
32+
33+
input + button {
34+
position: absolute;
35+
top: 1px;
36+
right: 1px;
37+
bottom: 1px;
38+
z-index: 2;
39+
border: none;
40+
background: $-input-background-color;
41+
42+
&:hover, &:focus, &:active {
43+
background: $-input-background-color;
44+
}
45+
46+
&.btn-danger {
47+
color: $-input-danger-color;
48+
}
49+
}
50+
}
51+
}
52+
}

tests/integration/components/ui-filter-test.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,9 @@ module('Integration | Component | ui-filter', function (hooks) {
313313

314314
assert.dom('table tbody tr').exists({ count: 11 });
315315

316-
assert
317-
.dom('.input-group .input-group-btn:last-child button')
318-
.hasAria('label', 'Reset Filter Input Field');
316+
assert.dom('.input-group button.ui-filter-reset').hasAria('label', 'Reset Filter Input Field');
319317

320-
await click('.input-group .input-group-btn:last-child button');
318+
await click('.input-group button.ui-filter-reset');
321319

322320
assert.dom('input[type="text"]').hasNoValue();
323321
});

0 commit comments

Comments
 (0)