Skip to content

Commit

Permalink
feat: Peer review
Browse files Browse the repository at this point in the history
  • Loading branch information
Trishu-Patel committed Dec 18, 2024
1 parent 46b5cb0 commit f9a8a2d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
6 changes: 2 additions & 4 deletions apps/docs-app/app/components/f/form/search.gts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import FreestyleSection from 'ember-freestyle/components/freestyle-section';

import CodeBlock from '../../code-block';

// TypeScript doesn't recognize that this function is used in the template
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function log(...msg: string[]) {
console.log(msg.join(' '));
}
Expand Down Expand Up @@ -105,10 +103,10 @@ export default class extends Component {
minCharacters = 1;

@tracked
noResultsLabel = 'No results found';
noResultsLabel;

@tracked
placeholder = 'Search';
placeholder;

@tracked
readonly = false;
Expand Down
12 changes: 6 additions & 6 deletions apps/test-app/tests/integration/components/form/search-test.gts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fillIn, render, click } from '@ember/test-helpers';
import { click, fillIn, render } from '@ember/test-helpers';
import { tracked } from '@glimmer/tracking';
import { Bind as bind, Search } from '@nrg-ui/core';
import { Search, bind } from '@nrg-ui/core';
import { module, test } from 'qunit';

import { setupRenderingTest } from '../../../helpers';
Expand All @@ -13,7 +13,7 @@ class Model {
module('Integration | Component | form/search', function (hooks) {
setupRenderingTest(hooks);

const actionHandler = (text) => {
const actionHandler = (text: string) => {
const fruits = [
'Apple',
'Banana',
Expand Down Expand Up @@ -132,7 +132,7 @@ module('Integration | Component | form/search', function (hooks) {

assert.dom('.spinner-border').doesNotExist();
assert.dom('.bi-search').doesNotExist();
assert.dom('button > i.bi-x-lg').doesNotExist();
assert.dom('button').doesNotExist();
});

test('it shows clear button', async function (assert) {
Expand All @@ -154,9 +154,9 @@ module('Integration | Component | form/search', function (hooks) {

assert.dom('div > input').hasValue('an');

assert.dom('button > i.bi-x-lg').exists();
assert.dom('button').exists();

await click('button > i.bi-x-lg');
await click('button');

assert.dom('div > input').hasValue('');
});
Expand Down
24 changes: 14 additions & 10 deletions packages/ember-core/src/components/form/search.gts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import { fn } from '@ember/helper';
import { on } from '@ember/modifier';
import { action, get } from '@ember/object';
import { service } from '@ember/service';
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { restartableTask, timeout } from 'ember-concurrency';
import { t } from 'ember-intl';
// @ts-expect-error Ember keyboard doesn't currently ship a type for the `on-key` modifier
// https://github.com/adopted-ember-addons/ember-keyboard/issues/464
import onKey from 'ember-keyboard/modifiers/on-key';

import BoundValue from './bound-value.ts';
import onClickOutside from '../../modifiers/on-click-outside.ts';
import onInsert from '../../modifiers/on-insert.ts';
import Button from '../button.gts';

import type { Optional } from '../../';
import type IntlService from 'ember-intl/services/intl';

declare type SearchOption<T> = {
label: string;
Expand All @@ -30,9 +34,6 @@ interface SearchItemSignature<T> {
}

class SearchItem<T> extends Component<SearchItemSignature<T>> {
@tracked
active = true;

get classList() {
const classes = ['dropdown-item'];

Expand Down Expand Up @@ -104,6 +105,9 @@ export default class Search<T> extends BoundValue<
@tracked
searchString = '';

@service
declare intl: IntlService;

get clearable() {
if (this.args.basic) {
return false;
Expand All @@ -129,15 +133,15 @@ export default class Search<T> extends BoundValue<
}

get noResultsLabel() {
return this.args.noResultsLabel ?? 'No results found';
return this.args.noResultsLabel ?? this.intl.t('nrg.search.noResults');
}

get placeholder() {
if (this.args.basic) {
return '';
}

return this.args.placeholder ?? 'Search';
return this.args.placeholder ?? this.intl.t('nrg.search.placeholder');
}

get scrollable() {
Expand Down Expand Up @@ -392,13 +396,13 @@ export default class Search<T> extends BoundValue<
{{onInsert this.onSearchBarInsert}}
/>
{{#if this.clearable}}
<button
class="input-group-text"
type="button"
{{on "click" this.clear}}
<Button
aria-label={{t "nrg.base.clear"}}
class="btn-outline-secondary"
@onClick={{this.clear}}
>
<i class="bi bi-x-lg" />
</button>
</Button>
{{/if}}
</div>
<div class="dropdown {{if this.scrollable 'scrollable'}}">
Expand Down
7 changes: 6 additions & 1 deletion packages/ember-core/translations/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
},
"loading": "Loading",
"next": "Next",
"previous": "Previous"
"previous": "Previous",
"clear" : "Clear"
},
"navbar": {
"toggleContextMenu": "Toggle context menu"
Expand All @@ -21,6 +22,10 @@
"select": {
"defaultText": "Select an Option"
},
"search": {
"placeholder": "Search",
"noResults": "No results found"
},
"validation": {
"confirmation": {
"invalid": "This field does not match {label}",
Expand Down

0 comments on commit f9a8a2d

Please sign in to comment.