Skip to content
This repository was archived by the owner on May 24, 2024. It is now read-only.

[terra-search-field] Removed the terra-form-input and replaced it with a native input #3078

Merged
merged 9 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/terra-search-field/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ ChangeLog

Unreleased
----------
### Removed
* Removed `terra-form-input` from dependencies.

### Changed
* Removed the terra-form-input and replaced it with a native input
* Updated wdio snapshots

### Added
* Added new theme variables
* Added test for disabled search-field with placeholder

3.53.0 - (July 7, 2020)
------------------
Expand Down
1 change: 0 additions & 1 deletion packages/terra-search-field/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"keycode-js": "^2.0.1",
"prop-types": "^15.5.8",
"terra-button": "^3.43.0",
"terra-form-input": "^3.7.0",
"terra-icon": "^3.33.0",
"terra-mixins": "^1.36.0",
"terra-theme-context": "^1.0.0"
Expand Down
7 changes: 3 additions & 4 deletions packages/terra-search-field/src/SearchField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import ThemeContext from 'terra-theme-context';
import Button from 'terra-button';
import * as KeyCode from 'keycode-js';
import IconSearch from 'terra-icon/lib/icon/IconSearch';
import Input from 'terra-form-input';
import { injectIntl, intlShape } from 'react-intl';
import styles from './SearchField.module.scss';

Expand Down Expand Up @@ -273,17 +272,17 @@ class SearchField extends React.Component {
return (
<div {...customProps} className={searchFieldClassNames}>
<div className={cx('input-group')}>
<Input
<input
className={cx('input')}
type="search"
placeholder={placeholder}
onChange={this.handleTextChange}
disabled={isDisabled}
ariaLabel={inputText}
aria-label={inputText}
aria-disabled={isDisabled}
onKeyDown={this.handleKeyDown}
onInput={this.handleInput}
refCallback={this.setInputRef}
ref={this.setInputRef}
{...additionalInputAttributes}
Copy link
Contributor

Choose a reason for hiding this comment

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

Previously, form-input will automatically add aria-required if required was passed to inputAttributes. Since this is no longer leveraging form-input, it would lose this logic. Should this be added here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I and @neilpfeiffer discussed this and decided that it is unneeded to make search-field a required field.

Copy link
Contributor

Choose a reason for hiding this comment

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

It maybe not be part of this scope, but in general we spread pass-through attributes before our implementation specific ones so the behaviors cannot be overridden. So I'd like to see this moved.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @dkasper-was-taken - logged this new issue here to move the spread to first in the list: #3086

/>
{clearButton}
Expand Down
93 changes: 77 additions & 16 deletions packages/terra-search-field/src/SearchField.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,6 @@
position: relative;
}

.input {
appearance: none;
border-bottom-left-radius: var(--terra-search-field-input-border-bottom-left-radius, 3px);
border-bottom-right-radius: 0;
border-top-left-radius: var(--terra-search-field-input-border-top-left-radius, 3px);
border-top-right-radius: 0;
flex: 1 1 auto;
margin-bottom: var(--terra-search-field-input-margin-bottom, 0);
margin-left: var(--terra-search-field-input-margin-left, 0);
margin-right: var(--terra-search-field-input-margin-right, 0);
margin-top: var(--terra-search-field-input-margin-top, 0);
min-width: 0;
outline-offset: -0.143em; // Adjust the outline offset for search input in Safari.
padding-right: var(--terra-search-field-input-padding-right, 2.28571rem); // Match the padding to width of the clear button
}

.input::-ms-clear,
.input::-ms-reveal {
display: none;
Expand Down Expand Up @@ -103,6 +87,83 @@
display: flex;
width: 100%;
}
}

.input {
appearance: none;
background-color: var(--terra-search-field-input-background-color, #fff);
background-image: none;
background-position: 0 100%;
background-repeat: no-repeat;
background-size: auto;
border: var(--terra-search-field-input-border, 1px solid #dedfe0);
border-bottom-left-radius: var(--terra-search-field-input-border-bottom-left-radius, 3px);
border-bottom-right-radius: 0;
border-top-left-radius: var(--terra-search-field-input-border-top-left-radius, 3px);
border-top-right-radius: 0;
box-shadow: none;
color: var(--terra-search-field-input-color, #1c1f21);
flex: 1 1 auto;
font-family: inherit;
font-size: var(--terra-search-field-input-font-size, 1.142857rem);
height: var(--terra-search-field-input-height, 2.142857rem);
line-height: 1.25;
margin-bottom: var(--terra-search-field-input-margin-bottom, 0);
margin-left: var(--terra-search-field-input-margin-left, 0);
margin-right: var(--terra-search-field-input-margin-right, 0);
margin-top: var(--terra-search-field-input-margin-top, 0);
min-width: 0;
outline-offset: -0.143em; // Adjust the outline offset for search input in Safari.
padding-bottom: var(--terra-search-field-input-padding-bottom, 0.28571rem);
padding-left: var(--terra-search-field-input-padding-left, 0.28571rem);
padding-right: var(--terra-search-field-input-padding-right, 2.28571rem); // Match the padding to width of the clear button
padding-top: var(--terra-search-field-input-padding-top, 0.28571rem);
transition-duration: 0s;
transition-property: background-size;
transition-timing-function: ease;
width: 100%;

&::placeholder {
color: var(--terra-search-field-input-placeholder-color, rgba(21, 33, 41, 0.62));
font-style: var(--terra-search-field-input-placeholder-font-style, italic);
opacity: 1;
}

&:hover {
background-color: var(--terra-search-field-input-hover-background-color, #fff);
border: var(--terra-search-field-input-hover-border, 1px solid #dedfe0);
color: var(--terra-search-field-input-hover-color);
}

&[disabled] {
background-color: var(--terra-search-field-input-disabled-background-color, rgba(111, 116, 119, 0.2));
border: var(--terra-search-field-input-disabled-border, 1px solid #868a8c);
color: var(--terra-search-field-input-disabled-color, #1c1f21);
cursor: default;
opacity: var(--terra-search-field-input-disabled-opacity, 0.25);
pointer-events: none;
}

&[disabled]::placeholder {
color: var(--terra-search-field-input-placeholder-disabled-color, rgba(21, 33, 41, 0.62));
font-style: var(--terra-search-field-input-placeholder-disabled-font-style, italic);
}

&:focus {
background-color: var(--terra-search-field-input-focus-background-color, #fff);
background-size: auto;
border: var(--terra-search-field-input-focus-border, 1px solid #4cb2e9);
box-shadow: var(--terra-search-field-input-focus-box-shadow);
color: var(--terra-search-field-input-focus-color);
outline: none;

[dir=ltr] & {
box-shadow: var(--terra-search-field-input-focus-ltr-box-shadow);
}

[dir=rtl] & {
box-shadow: var(--terra-search-field-input-focus-rtl-box-shadow);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should reduce these styles/variables as much as possible and apply only the ones necessary for theming the search field appropriately. Are all terra-form-input variables required to theme the search field?

Copy link
Contributor Author

@pranav300 pranav300 Jul 21, 2020

Choose a reason for hiding this comment

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

Are all terra-form-input variables required to theme the search field?

I had imported only the ones that were used by search-field when it imported form-input.
But still, I have gone through the CSS and removed some variables which I think were unnecessary here 468041b.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,39 @@
--terra-search-field-button-margin-right: 0;
--terra-search-field-button-margin-top: 0;
--terra-search-field-button-focus-box-shadow: #004c76;


--terra-search-field-input-background-color: #222a2e;
--terra-search-field-input-border: 1px solid #181b1d;
--terra-search-field-input-color: #b2b5b6;
--terra-search-field-input-font-size: 1.14285714rem;
--terra-search-field-input-height: 2.14285714rem;
--terra-search-field-input-padding-bottom: 0.28571rem;
--terra-search-field-input-padding-left: 0.28571rem;
--terra-search-field-input-padding-top: 0.28571rem;

--terra-search-field-input-hover-background-color: #222a2e;
--terra-search-field-input-hover-color: #b2b5b6;
--terra-search-field-input-hover-border: 1px solid #181b1d;

--terra-search-field-input-placeholder-color: #6f7477;
--terra-search-field-input-placeholder-font-style: normal;

--terra-search-field-input-disabled-background-color: #1d2529;
--terra-search-field-input-disabled-border: 1px solid #242b2b;
--terra-search-field-input-disabled-color: #404344;
--terra-search-field-input-disabled-opacity: 0.25;

--terra-search-field-input-placeholder-disabled-color: #6f7477;
--terra-search-field-input-placeholder-disabled-font-style: italic;

--terra-search-field-input-focus-background-color: #222a2e;
--terra-search-field-input-focus-border: 1px solid #004c76;
--terra-search-field-input-focus-box-shadow: 0 0 1px 3px #004c76, 0 0 7px 4px #004c76;
--terra-search-field-input-focus-color: #b2b5b6;

--terra-search-field-input-focus-ltr-box-shadow: none;
--terra-search-field-input-focus-rtl-box-shadow: none;

@include terra-inline-svg-var('--terra-search-field-clear-icon-background-image', '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48"><path fill="#b2b5b6" d="M24 0C10.7 0 0 10.7 0 24s10.7 24 24 24 24-10.7 24-24S37.3 0 24 0zm13.9 33.8l-2.1 2.1-1.2 1.2-1 .9-9.6-9.7-9.6 9.7-2.2-2.1-1.1-1.1-1-1 9.7-9.8-9.7-9.8 1-1 1.1-1.1 2.2-2.1 9.6 9.7 9.6-9.7 1 .9 1.2 1.2 2.1 2.1-9.7 9.8 9.7 9.8z"/></svg>');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,38 @@
--terra-search-field-button-margin-top: 0;
--terra-search-field-button-focus-box-shadow: inset 0 3rem 1.5rem -2rem #f4f4f4, 0 0 1px 1px rgba(255, 255, 255, 0.65), 0 0 2px 3px rgba(76, 178, 233, 0.5), 0 0 6px 4px rgba(76, 178, 233, 0.3);

--terra-search-field-input-background-color: #fff;
--terra-search-field-input-border: 1px solid #dedfe0;
--terra-search-field-input-color: #1c1f21;
--terra-search-field-input-font-size: 1rem;
--terra-search-field-input-height: 2.16667rem;
--terra-search-field-input-padding-bottom: 0.25rem;
--terra-search-field-input-padding-left: 0.25rem;
--terra-search-field-input-padding-top: 0.25rem;

--terra-search-field-input-hover-background-color: #fff;
--terra-search-field-input-hover-border: 1px solid #dedfe0;
--terra-search-field-input-hover-color: #1c1f21;

--terra-search-field-input-placeholder-color: #707070;
--terra-search-field-input-placeholder-font-style: normal;

--terra-search-field-input-disabled-background-color: #f4f4f4;
--terra-search-field-input-disabled-border: 1px solid #b2b5b6;
--terra-search-field-input-disabled-color: #9b9fa1;
--terra-search-field-input-disabled-opacity: 1;

--terra-search-field-input-placeholder-disabled-color: #c4c6c7;
--terra-search-field-input-placeholder-disabled-font-style: normal;

--terra-search-field-input-focus-background-color: #fff;
--terra-search-field-input-focus-border: 1px solid #4cb2e9;
--terra-search-field-input-focus-box-shadow: 0 0 8px #a6d9f4;
--terra-search-field-input-focus-color: #1c1f21;

--terra-search-field-input-focus-ltr-box-shadow: 0 0 8px #a6d9f4;
--terra-search-field-input-focus-rtl-box-shadow: 0 0 8px #a6d9f4;

@include terra-inline-svg-var('--terra-search-field-clear-icon-background-image', '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48"><path fill="#909496" d="M24 0C10.7 0 0 10.7 0 24s10.7 24 24 24 24-10.7 24-24S37.3 0 24 0zm13.9 33.8l-2.1 2.1-1.2 1.2-1 .9-9.6-9.7-9.6 9.7-2.2-2.1-1.1-1.1-1-1 9.7-9.8-9.7-9.8 1-1 1.1-1.1 2.2-2.1 9.6 9.7 9.6-9.7 1 .9 1.2 1.2 2.1 2.1-9.7 9.8 9.7 9.8z"/></svg>');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const SearchFieldPlaceholder = () => {
return (
<div>
<p>{message}</p>
<SearchField onSearch={setSearchText} onInvalidSearch={setSearchText} placeholder="Search Here" />
<SearchField onSearch={setSearchText} onInvalidSearch={setSearchText} placeholder="- Search Here -" />
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import SearchField from '../../../SearchField';

export default () => <SearchField id="searchfield" placeholder="Search Text" />;
export default () => <SearchField id="searchfield" placeholder="- Search Text -" />;
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import SearchField from '../../../SearchField';

export default () => <SearchField id="searchfield" placeholder="Search Text" />;
export default () => <SearchField id="searchfield" placeholder="- Search Text -" />;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import React from 'react';
import SearchField from '../../../SearchField';

export default () => <SearchField id="searchfield" placeholder="- Search Text -" isDisabled />;
Loading