Skip to content

Commit

Permalink
fix(item): add input highlight using an absolute div (#15856)
Browse files Browse the repository at this point in the history
Adds the following CSS properties to item:

```
--highlight-color-focused
--highlight-color-valid
--highlight-color-invalid
--highlight-height
```

This also fixes an issue where we were showing the highlight on items
with no lines, and shows inset vs full properly. Adds documentation and tests for input focus.

fixes #14036 fixes #9639 fixes #14952 closes #15690
  • Loading branch information
brandyscarney authored Oct 5, 2018
1 parent 23df042 commit f885f7d
Show file tree
Hide file tree
Showing 12 changed files with 266 additions and 90 deletions.
4 changes: 2 additions & 2 deletions angular/src/directives/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,12 +363,12 @@ export class Input {
}

export declare interface Item extends StencilComponents<'IonItem'> {}
@Component({ selector: 'ion-item', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, template: '<ng-content></ng-content>', inputs: ['color', 'mode', 'button', 'detail', 'detailIcon', 'disabled', 'href', 'lines', 'routerDirection', 'state', 'type'] })
@Component({ selector: 'ion-item', changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, template: '<ng-content></ng-content>', inputs: ['color', 'mode', 'button', 'detail', 'detailIcon', 'disabled', 'href', 'lines', 'routerDirection', 'type'] })
export class Item {

constructor(r: ElementRef) {
const el = r.nativeElement;
proxyInputs(this, el, ['color', 'mode', 'button', 'detail', 'detailIcon', 'disabled', 'href', 'lines', 'routerDirection', 'state', 'type']);
proxyInputs(this, el, ['color', 'mode', 'button', 'detail', 'detailIcon', 'disabled', 'href', 'lines', 'routerDirection', 'type']);
}
}

Expand Down
4 changes: 1 addition & 3 deletions core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2107,7 +2107,6 @@ export namespace Components {
* When using a router, it specifies the transition direction when navigating to another page using `href`.
*/
'routerDirection'?: RouterDirection;
'state'?: 'valid' | 'invalid' | 'focus';
/**
* The type of the button. Only used when an `onclick` or `button` property is present. Possible values are: `"submit"`, `"reset"` and `"button"`. Default value is: `"button"`
*/
Expand Down Expand Up @@ -2150,7 +2149,6 @@ export namespace Components {
* When using a router, it specifies the transition direction when navigating to another page using `href`.
*/
'routerDirection'?: RouterDirection;
'state'?: 'valid' | 'invalid' | 'focus';
/**
* The type of the button. Only used when an `onclick` or `button` property is present. Possible values are: `"submit"`, `"reset"` and `"button"`. Default value is: `"button"`
*/
Expand Down Expand Up @@ -4017,7 +4015,7 @@ export namespace Components {
* The text to display on the ok button. Default: `OK`.
*/
'okText': string;
'open': (ev?: UIEvent | undefined) => Promise<HTMLIonActionSheetElement | HTMLIonAlertElement | HTMLIonPopoverElement>;
'open': (ev?: UIEvent | undefined) => Promise<HTMLIonAlertElement | HTMLIonPopoverElement | HTMLIonActionSheetElement>;
/**
* The text to display when the select is empty.
*/
Expand Down
1 change: 0 additions & 1 deletion core/src/components/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ export class Input implements ComponentInterface {
return {
class: {
...createColorClasses(this.color),

'in-item': hostContext('ion-item', this.el),
'has-value': this.hasValue(),
'has-focus': this.hasFocus
Expand Down
29 changes: 28 additions & 1 deletion core/src/components/input/test/basic/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,33 @@ it('input: basic', async () => {
url: '/src/components/input/test/basic?ionic:animated=false'
});

const compare = await page.compareScreenshot();
let compare = await page.compareScreenshot();
expect(compare).toMatchScreenshot();

const fullInput = await page.find('#fullInput');
await fullInput.click();

const fullItem = await page.find('#fullItem');
expect(fullItem).toHaveClass('item-has-focus');

compare = await page.compareScreenshot('full input focused');
expect(compare).toMatchScreenshot();

const insetInput = await page.find('#insetInput');
await insetInput.click();

const insetItem = await page.find('#insetItem');
expect(insetItem).toHaveClass('item-has-focus');

compare = await page.compareScreenshot('inset input focused');
expect(compare).toMatchScreenshot();

const noneInput = await page.find('#noneInput');
await noneInput.click();

const noneItem = await page.find('#noneItem');
expect(noneItem).toHaveClass('item-has-focus');

compare = await page.compareScreenshot('no lines input focused');
expect(compare).toMatchScreenshot();
});
12 changes: 12 additions & 0 deletions core/src/components/input/test/basic/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@
<ion-input placeholder="Placeholder"></ion-input>
</ion-item>

<ion-item lines="full" id="fullItem">
<ion-input id="fullInput" placeholder="Full"></ion-input>
</ion-item>

<ion-item lines="inset" id="insetItem">
<ion-input id="insetInput" placeholder="Inset"></ion-input>
</ion-item>

<ion-item lines="none" id="noneItem">
<ion-input id="noneInput" placeholder="None"></ion-input>
</ion-item>

<ion-item>
<ion-label>Default Label</ion-label>
<ion-input value="reallylonglonglonginputtoseetheedgesreallylonglonglonginputtoseetheedges"></ion-input>
Expand Down
23 changes: 18 additions & 5 deletions core/src/components/item/item.ios.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,17 @@
--padding-start: #{$item-ios-padding-start};
--inner-padding-end: #{$item-ios-padding-end / 2};
--inner-border-width: #{0px 0px $item-ios-border-bottom-width 0px};

font-size: $item-ios-font-size;
}

:host(:not(.ion-color)) {
--background: var(--ion-item-background-color, transparent);
--background-activated: #{$item-ios-background-color-active};
--border-color: #{$item-ios-border-bottom-color};
--color: #{$item-ios-text-color};
--detail-icon-color: #{$item-ios-border-bottom-color};
--highlight-height: 0;
--highlight-color-focused: #{$item-ios-input-highlight-color};
--highlight-color-valid: #{$item-ios-input-highlight-color-valid};
--highlight-color-invalid: #{$item-ios-input-highlight-color-invalid};

font-size: $item-ios-font-size;
}

:host(.activated) {
Expand All @@ -29,14 +30,24 @@
// iOS Item Lines
// --------------------------------------------------

// Default input items have an inset border
:host(.item-interactive) {
--show-full-highlight: 0;
--show-inset-highlight: 1;
}

// Full lines - apply the border to the item
// Inset lines - apply the border to the item inner
:host(.item-lines-full) {
--border-width: #{0px 0px $item-ios-border-bottom-width 0px};
--show-full-highlight: 1;
--show-inset-highlight: 0;
}

:host(.item-lines-inset) {
--inner-border-width: #{0px 0px $item-ios-border-bottom-width 0px};
--show-full-highlight: 0;
--show-inset-highlight: 1;
}

// Full lines - remove the border from the item inner (inset list items)
Expand All @@ -45,11 +56,13 @@
:host(.item-lines-inset),
:host(.item-lines-none) {
--border-width: 0px;
--show-full-highlight: 0;
}

:host(.item-lines-full),
:host(.item-lines-none) {
--inner-border-width: 0px;
--show-inset-highlight: 0;
}


Expand Down
9 changes: 9 additions & 0 deletions core/src/components/item/item.ios.vars.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ $item-ios-border-bottom-color: $item-ios-border-color !default;
/// @prop - Border bottom for the item
$item-ios-border-bottom: $item-ios-border-bottom-width $item-ios-border-bottom-style $item-ios-border-bottom-color !default;

/// @prop - Color of the item input highlight
$item-ios-input-highlight-color: ion-color(primary, base) !default;

/// @prop - Color of the item input highlight when valid
$item-ios-input-highlight-color-valid: ion-color(success, base) !default;

/// @prop - Color of the item input highlight when invalid
$item-ios-input-highlight-color-invalid: ion-color(danger, base) !default;


// Item Slots
// --------------------------------------------------
Expand Down
30 changes: 20 additions & 10 deletions core/src/components/item/item.md.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,48 @@
:host {
--transition: background-color 300ms cubic-bezier(.4, 0, .2, 1);
--padding-start: #{$item-md-padding-start};
--background: var(--ion-item-background-color, transparent);
--background-activated: #{$item-md-background-color-active};
--color: #{$item-md-text-color};
--border-color: #{$item-md-border-bottom-color};
--inner-padding-end: #{$item-md-padding-end / 2};
--padding-start: #{$item-md-padding-start};
--inner-border-width: #{0 0 $item-md-border-bottom-width 0};
--detail-icon-color: #{$item-md-border-bottom-color};
--highlight-height: 2px;
--highlight-color-focused: #{$item-md-input-highlight-color};
--highlight-color-valid: #{$item-md-input-highlight-color-valid};
--highlight-color-invalid: #{$item-md-input-highlight-color-invalid};

font-size: $item-md-font-size;
font-weight: normal;

text-transform: none;
}

:host(:not(.ion-color)) {
--background: var(--ion-item-background-color, transparent);
--background-activated: #{$item-md-background-color-active};
--border-color: #{$item-md-border-bottom-color};
--color: #{$item-md-text-color};
--detail-icon-color: #{$item-md-border-bottom-color};
}


// Material Design Item Lines
// --------------------------------------------------

// Default input items have a border
// Default input items have a full border
:host(.item-interactive) {
--border-width: #{0 0 $item-md-border-bottom-width 0};
--inner-border-width: 0;
--show-full-highlight: 1;
--show-inset-highlight: 0;
}

// Full lines - apply the border to the item
// Inset lines - apply the border to the item inner
:host(.item-lines-full) {
--border-width: #{0 0 $item-md-border-bottom-width 0};
--show-full-highlight: 1;
--show-inset-highlight: 0;
}

:host(.item-lines-inset) {
--inner-border-width: #{0 0 $item-md-border-bottom-width 0};
--show-full-highlight: 0;
--show-inset-highlight: 1;
}

// Full lines - remove the border from the item inner (inset list items)
Expand All @@ -50,11 +58,13 @@
:host(.item-lines-inset),
:host(.item-lines-none) {
--border-width: 0;
--show-full-highlight: 0;
}

:host(.item-lines-full),
:host(.item-lines-none) {
--inner-border-width: 0;
--show-inset-highlight: 0;
}

// Material Design Item Detail Push
Expand Down
9 changes: 9 additions & 0 deletions core/src/components/item/item.md.vars.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ $item-md-border-bottom-color: $item-md-border-color !default;
/// @prop - Border bottom for the item when lines are displayed
$item-md-border-bottom: $item-md-border-bottom-width $item-md-border-bottom-style $item-md-border-color !default;

/// @prop - Color of the item input highlight
$item-md-input-highlight-color: ion-color(primary, base) !default;

/// @prop - Color of the item input highlight when valid
$item-md-input-highlight-color-valid: ion-color(success, base) !default;

/// @prop - Color of the item input highlight when invalid
$item-md-input-highlight-color-invalid: ion-color(danger, base) !default;


// Item Slots
// --------------------------------------------------
Expand Down
Loading

0 comments on commit f885f7d

Please sign in to comment.