Skip to content

Commit

Permalink
Merge pull request #2691 from ONSdigital/enhancement/2177/update-sear…
Browse files Browse the repository at this point in the history
…ch-macro-implementation

Enhancement/2177/update search macro implementation
  • Loading branch information
alessioventuriniAND authored Jun 26, 2023
2 parents 1a9d818 + 26a04e8 commit 3c4d2b0
Show file tree
Hide file tree
Showing 25 changed files with 39 additions and 174 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/components/input/_input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@
}
}

.ons-input_search-button {
display: flex;
flex-flow: row nowrap !important;
gap: 0.5rem;
}

.ons-input-search {
@extend .ons-input--block;
@extend .ons-input--ghost;
Expand Down
31 changes: 19 additions & 12 deletions src/components/input/_macro.njk
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{% macro onsInput(params) %}
{% from "components/mutually-exclusive/_macro.njk" import onsMutuallyExclusive %}
{% from "components/char-check-limit/_macro.njk" import onsCharLimit %}
{% from "components/search/_macro.njk" import onsSearch %}
{% from "components/field/_macro.njk" import onsField %}
{% from "components/label/_macro.njk" import onsLabel %}
{% from "components/button/_macro.njk" import onsButton %}

{% if params.type == "number" %}
{# Type must be "text" or Firefox and Safari will set a blank value to the server if non numeric characters are entered -
Expand Down Expand Up @@ -100,21 +100,28 @@
</span>
{% endif %}
{% elif params.searchButton %}
<span class="ons-grid--flex ons-search">
{% call onsSearch({
"accessiblePlaceholder": params.accessiblePlaceholder,
"searchButton": {
<span class="ons-grid--flex ons-input_search-button">
{{ input | safe }}
{%- set buttonLabel -%}
{%- if params.searchButton.visuallyHideButtonText == true -%}
<span class="ons-u-vh">{{ params.searchButton.text }}</span>
{%- else -%}
{{ params.searchButton.text }}
{%- endif -%}
{%- endset -%}
{{
onsButton({
"type": params.searchButton.type,
"html": buttonLabel,
"text": params.searchButton.text,
"visuallyHideButtonText": params.searchButton.visuallyHideButtonText,
"id": params.searchButton.id,
"variants": 'small',
"classes": 'ons-search__btn' + (" " + params.searchButton.classes if params.searchButton.classes else ""),
"attributes": params.searchButton.attributes,
"classes": params.searchButton.classes,
"iconType": params.searchButton.iconType
}
}) %}
{{ input | safe }}
{% endcall %}
"iconType": params.searchButton.iconType,
"iconPosition": 'only' if params.searchButton.visuallyHideButtonText == true else 'before'
})
}}
</span>
{% else %}
{{ input | safe }}
Expand Down
20 changes: 0 additions & 20 deletions src/components/input/_macro.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,26 +535,6 @@ describe('macro: input', () => {
});

describe('search', () => {
it('renders `search` component', () => {
const faker = templateFaker();
const searchSpy = faker.spy('search');

faker.renderComponent('input', EXAMPLE_WITH_SEARCH);

expect(searchSpy.occurrences[0]).toEqual({
accessiblePlaceholder: true,
searchButton: {
type: 'button',
text: 'Search for address',
id: 'search-for-address',
attributes: { a: 42 },
classes: 'extra-search-button-class',
iconType: 'search',
visuallyHideButtonText: true,
},
});
});

it.each('outputs `type` attribute of "search"', () => {
const $ = cheerio.load(renderComponent('input', EXAMPLE_WITH_SEARCH));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% from "components/input/_macro.njk" import onsInput %}

{{
onsInput({
"id": 'search-field',
Expand All @@ -20,4 +19,4 @@
"charCountOverLimitPlural": "{x} characters too many"
}
})
}}
}}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% from "components/input/_macro.njk" import onsInput %}

{{
onsInput({
"id": 'search-field',
Expand All @@ -13,4 +12,4 @@
"iconType": 'search'
}
})
}}
}}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% from "components/input/_macro.njk" import onsInput %}

{{
onsInput({
"id": 'search-field',
Expand All @@ -13,4 +12,4 @@
"iconType": 'search'
}
})
}}
}}
16 changes: 0 additions & 16 deletions src/components/search/_macro-options.md

This file was deleted.

30 changes: 0 additions & 30 deletions src/components/search/_macro.njk

This file was deleted.

69 changes: 0 additions & 69 deletions src/components/search/_macro.spec.js

This file was deleted.

9 changes: 0 additions & 9 deletions src/components/search/_search.scss

This file was deleted.

1 change: 0 additions & 1 deletion src/scss/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
@import '../components/radios/radios';
@import '../components/related-content/related-content';
@import '../components/relationships/relationships';
@import '../components/search/search';
@import '../components/section-navigation/section-navigation';
@import '../components/skip-to-content/skip';
@import '../components/status/status';
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13278,4 +13278,4 @@ yup@^0.27.0:
zwitch@^1.0.0:
version "1.0.5"
resolved "https://registry.yarnpkg.com/zwitch/-/zwitch-1.0.5.tgz#d11d7381ffed16b742f6af7b3f223d5cd9fe9920"
integrity sha512-V50KMwwzqJV0NpZIZFwfOD5/lyny3WlSzRiXgA0G7VUnRlqttta1L6UQIHzd6EuBY/cHGfwTIck7w1yH6Q5zUw==
integrity sha512-V50KMwwzqJV0NpZIZFwfOD5/lyny3WlSzRiXgA0G7VUnRlqttta1L6UQIHzd6EuBY/cHGfwTIck7w1yH6Q5zUw==

0 comments on commit 3c4d2b0

Please sign in to comment.