-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(text-field): Add ripple to outlined text field #1807
Changes from 11 commits
d09deea
c97e81b
b15172e
8cc9ae1
b491f77
07bac11
855dacd
771d0ac
341329c
7be08de
1250a18
b12d5c2
a4a7009
ac8d407
4821f39
8772351
ded1572
a0292e5
f4292f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,22 +21,64 @@ The outline is a border around all sides of the text field. This is used for the | |
|
||
## Usage | ||
|
||
#### MDCTextFieldOutline API | ||
### HTML Structure | ||
|
||
##### MDCTextFieldOutline.foundation | ||
```html | ||
<div class="mdc-text-field__outline"> | ||
<svg> | ||
<path class="mdc-text-field__outline-path"/> | ||
</svg> | ||
</div> | ||
<div class="mdc-text-field__idle-outline"></div> | ||
``` | ||
|
||
MDCTextFieldOutlineFoundation. This allows the parent MDCTextField component to access the public methods on the MDCTextFieldOutlineFoundation class. | ||
### Usage within `mdc-text-field` | ||
|
||
### Using the foundation class | ||
```html | ||
<div class="mdc-text-field mdc-text-field--outlined"> | ||
<input class="mdc-text-field__input" id="my-text-field-id" type="text"> | ||
<label class="mdc-text-field__label" for="my-text-field-id">Label</label> | ||
<div class="mdc-text-field__outline"> | ||
<svg> | ||
<path class="mdc-text-field__outline-path"/> | ||
</svg> | ||
</div> | ||
<div class="mdc-text-field__idle-outline"></div> | ||
</div> | ||
``` | ||
|
||
### CSS Classes | ||
|
||
CSS Class | Description | ||
--- | --- | ||
`mdc-text-field__outline` | Mandatory | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No actual descriptions? |
||
`mdc-text-field__outline-path` | Mandatory | ||
`mdc-text-field__idle-outline` | Mandatory | ||
|
||
#### `MDCTextFieldOutline` | ||
|
||
Method Signature | Description | ||
--- | --- | ||
getWidth() => number | Returns the width of the outline element | ||
getHeight() => number | Returns the height of the outline element | ||
setOutlinePathAttr(value: string) => void | Sets the "d" attribute of the outline element's SVG path | ||
`MDCTextFieldOutline.createRipple(rippleFactory, rippleInputMethods) => MDCRipple` | Returns an `MDCRipple` instance set on the `mdc-text-field__outline` element | ||
|
||
##### `MDCTextFieldOutline.foundation` | ||
|
||
This allows the parent `MDCTextField` component to access the public methods on the `MDCTextFieldOutlineFoundation` class. | ||
|
||
##### `MDCTextFieldOutline.createRipple(rippleFactory: (function(!Element, !MDCRippleFoundation): !MDCRipple), foundation: !MDCRippleFoundation)` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we tend to not include the |
||
|
||
#### The full foundation API | ||
Returns an `MDCRipple` instance set on the `mdc-text-field__outline` element, which will be used by the parent `MDCTextField` component. | ||
|
||
##### MDCTextFieldOutlineFoundation.updateSvgPath(width: number, height: number, labelWidth: number, radius: number, isRtl: boolean) | ||
### `MDCTextFieldOutlineAdapter` | ||
|
||
Updates the SVG path of the focus outline element based on the given width and height of the text field element, the width of the label element, the corner radius, and the RTL context. | ||
Method Signature | Description | ||
--- | --- | ||
`getWidth() => number` | Returns the width of the outline element | ||
`getHeight() => number` | Returns the height of the outline element | ||
`setOutlinePathAttr(value: string) => void` | Sets the "d" attribute of the outline element's SVG path | ||
|
||
### `MDCTextFieldOutlineFoundation` | ||
|
||
Method Signature | Description | ||
--- | --- | ||
`updateSvgPath(labelWidth: number, radius: number, isRtl: boolean) => void` | Updates the SVG path of the focus outline element based on the given the width of the label element, the corner radius, and the RTL context. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,10 @@ | |
} | ||
|
||
.mdc-text-field__outline { | ||
@include mdc-ripple-surface; | ||
@include mdc-states-base-color(black); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this line; the next line will already result in including There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is necessary now that we're using just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True (I hadn't tested the behavior prior to writing that comment), but should it be using |
||
@include mdc-states(text-primary-on-light); | ||
@include mdc-ripple-radius; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Move this above |
||
@include mdc-theme-prop(color, primary); | ||
@include mdc-text-field-outlined-corner-radius($mdc-text-field-border-radius); | ||
|
||
|
@@ -44,17 +48,18 @@ | |
transition: mdc-text-field-transition(opacity); | ||
opacity: 0; | ||
z-index: 2; | ||
overflow: hidden; | ||
|
||
svg { | ||
position: absolute; | ||
width: 100%; | ||
height: 100%; | ||
|
||
.mdc-text-field__outline-path { | ||
@include mdc-theme-prop(stroke, primary); | ||
|
||
stroke-width: 2px; | ||
transition: mdc-text-field-transition(stroke-width), mdc-text-field-transition(opacity); | ||
stroke: $mdc-text-field-outlined-idle-border; | ||
stroke-width: 1px; | ||
transition: mdc-text-field-transition(stroke), mdc-text-field-transition(stroke-width), | ||
mdc-text-field-transition(opacity); | ||
fill: transparent; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems a bit overboard to me to have a separate method on the outline subcomponent that does exactly the same thing as above, and requiring us to pass everything through to it, when the only difference is which element the ripple is instantiated on.
I also find it a bit strange since the ripple is still destroyed from the top level component, and there's nothing really "owning" it from the outline subcomponent.
Given that the branching logic is here anyway, should we simply conditionalize which element the ripple is created on here and otherwise have the same code for both in one place?
Another thought: should the decision of which element hosts the ripple be determined within an API for the top-level foundation, so that component implementors have less logic to worry about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for the separate method on the outline subcomponent is because we need access to the outline's root element to instantiate the ripple on. The other option was to have a public
getRoot()
method in the outline, which seems to break best practices....although that might seem less weird than having an entirecreateRipple()
method on a subcomponent that doesn't even own the ripple. Thoughts?Moving the ripple host decision to the foundation seems even more complicated since the main foundation would have to somehow access the outline subcomponent (don't know if this is possible, maybe through the outline subadapter?...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would argue that we already have access to the outline subcomponent's root element:
outlineElement
. We just passed it to the subcomponent constructor about 30 lines above in this same method.And...yeah my idea about making the foundation decide ends up being pretty awkward, so nevermind about that one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
D'oh, huge brain fart on my part. Updated it to share the same code except for conditionalizing on which element the ripple is created on.