-
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
refactor(notched-outline): remove text-field notched outline styles and coupling #2401
Changes from 101 commits
a9d6c3c
9b750cd
4b01134
5a4500f
324a638
51f16f6
af02b19
6f9abdf
028c00d
024ff39
2f72c61
c2f6b95
f452125
f00ef39
4a9846c
1f2cf62
ab8b035
040f739
d3871a3
252ffc4
43bd881
9b627e2
808b6ff
bed6857
2c1c55e
d7e1776
8a03462
5973760
8385248
182b4b1
ce05cda
1a0aa6c
7f69180
f8ca6f1
161e40a
d6a5606
eb3893f
da53da7
ead024d
78f5b2d
8a05219
60467b6
466e7e6
699da0a
ca134d9
67c1ab8
d7e6962
d76fedc
91ad0a9
edc898b
5dbf686
6fdbafc
30b59cb
2ae20d1
f03ca0e
957fa3c
7d3a17c
5247b43
cf75c3b
fbce528
4237987
f556712
f772800
a14f34a
0898056
c46fa37
5d19c87
c2a9737
3bfdcf2
5efdf4f
4d4c4fe
b98ae09
b7b9ce7
39af4be
fc35362
2a30f0d
9b539e0
db85d16
adf5817
a2ce01b
19cc126
3f3ca89
f351e17
1a42cd7
323552d
6606984
526a69f
79d67b4
67bb0a5
e9141ea
0a6294c
9378b7c
8157968
e49a03b
142a142
0ec3a8f
74fc299
b32fc7b
61e3d88
0656a9e
cc391d2
f2e604b
4d8dc0e
509e530
d334297
a630847
0634366
c015302
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 |
---|---|---|
|
@@ -39,6 +39,7 @@ The outline is a border around all sides of either a text field or select compon | |
CSS Class | Description | ||
--- | --- | ||
`mdc-notched-outline` | Mandatory. Container for the SVG of the notched outline path. | ||
`mdc-notched-outline--notched` | Class to activate notch outline. | ||
`mdc-notched-outline__path` | Mandatory. The path of the SVG of the notched outline. | ||
`mdc-notched-outline__idle` | Mandatory. The full outline when the notch is hidden. | ||
|
||
|
@@ -82,6 +83,7 @@ Mixin | Description | |
|
||
Method Signature | Description | ||
--- | --- | ||
`notch(activateNotch: boolean)` | Updates outline to activate/deactivate notch in outline path. | ||
`updateSvgPath(notchWidth: number, isRtl: boolean) => void` | Updates the SVG of the outline element with a notch calculated based off of the notchWidth. The notch will appear left justified, unless isRtl is true. | ||
|
||
### `MDCNotchedOutlineAdapter` | ||
|
@@ -90,14 +92,14 @@ Method Signature | Description | |
--- | --- | ||
`getWidth() => number` | Returns the width of the outline element. | ||
`getHeight() => number` | Returns the height of the outline element. | ||
`addClass(className: string) => void` | Adds a class to the notched outline element. | ||
`removeClass(className: string) => void` | Removes a class from the notched outline element. | ||
`setOutlinePathAttr(value: string) => void` | Sets the "d" attribute of the outline element's SVG path. | ||
`getIdleOutlineStyleValue(propertyName: string) => string` | Returns the idle outline element's computed style value of a given css `propertyName`. | ||
|
||
### `MDCNotchedOutlineFoundation` | ||
|
||
Method Signature | Description | ||
--- | --- | ||
`notch(activateNotch: boolean)` | Adds remove the outline notched selector if activateNotch is true. Updates the component to activate/deactivate notched outline. | ||
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 this description needs to be reworded. Maybe just the second sentence is needed |
||
`updateSvgPath(notchWidth: number, isRtl: boolean) => void` | Updates the SVG path of the focus outline element based on the given notchWidth and the RTL context. | ||
|
||
|
||
[//]: <> (TODO(mattgoo): add how to hide/show notch in outline) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
|
||
import MDCFoundation from '@material/base/foundation'; | ||
import MDCNotchedOutlineAdapter from './adapter'; | ||
import {strings} from './constants'; | ||
import {cssClasses, strings} from './constants'; | ||
|
||
/** | ||
* @extends {MDCFoundation<!MDCNotchedOutlineAdapter>} | ||
|
@@ -29,6 +29,11 @@ class MDCNotchedOutlineFoundation extends MDCFoundation { | |
return strings; | ||
} | ||
|
||
/** @return enum {string} */ | ||
static get cssClasses() { | ||
return cssClasses; | ||
} | ||
|
||
/** | ||
* {@see MDCNotchedOutlineAdapter} for typing information on parameters and return | ||
* types. | ||
|
@@ -38,6 +43,8 @@ class MDCNotchedOutlineFoundation extends MDCFoundation { | |
return /** @type {!MDCNotchedOutlineAdapter} */ ({ | ||
getWidth: () => {}, | ||
getHeight: () => {}, | ||
addClass: () => {}, | ||
removeClass: () => {}, | ||
setOutlinePathAttr: () => {}, | ||
getIdleOutlineStyleValue: () => {}, | ||
}); | ||
|
@@ -50,13 +57,31 @@ class MDCNotchedOutlineFoundation extends MDCFoundation { | |
super(Object.assign(MDCNotchedOutlineFoundation.defaultAdapter, adapter)); | ||
} | ||
|
||
/** | ||
* Adds the outline notched selector and updates the notch width | ||
* if activateNotch is true, otherwise it will remove notched | ||
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 the notched selector" |
||
* selector. | ||
* @param {number} notchWidth | ||
* @param {boolean=} isRtl | ||
*/ | ||
notch(notchWidth, isRtl = false) { | ||
const {OUTLINE_NOTCHED} = MDCNotchedOutlineFoundation.cssClasses; | ||
if (notchWidth > 0) { | ||
this.adapter_.addClass(OUTLINE_NOTCHED); | ||
this.updateSvgPath_(notchWidth, isRtl); | ||
} else { | ||
this.adapter_.removeClass(OUTLINE_NOTCHED); | ||
} | ||
} | ||
|
||
/** | ||
* Updates the SVG path of the focus outline element based on the notchWidth | ||
* and the RTL context. | ||
* @param {number} notchWidth | ||
* @param {boolean=} isRtl | ||
* @private | ||
*/ | ||
updateSvgPath(notchWidth, isRtl = false) { | ||
updateSvgPath_(notchWidth, isRtl) { | ||
// Fall back to reading a specific corner's style because Firefox doesn't report the style on border-radius. | ||
const radiusStyleValue = this.adapter_.getIdleOutlineStyleValue('border-radius') || | ||
this.adapter_.getIdleOutlineStyleValue('border-top-left-radius'); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -248,7 +248,7 @@ Method Signature | Description | |
`isFocused() => boolean` | Returns whether the input is focused | ||
`isRtl() => boolean` | Returns whether the direction of the root element is set to RTL | ||
`hasOutline() => boolean` | Returns whether there is an outline element | ||
`updateOutlinePath(labelWidth: number, isRtl: boolean) => void` | Updates the outline path to create a notch for the label element | ||
`notchOutline(labelWidth: number, isRtl: boolean) => void` | Updates the outline path to create a notch for the label element | ||
|
||
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. Do you also need a |
||
#### `MDCTextFieldAdapter.getNativeInput()` | ||
|
||
|
@@ -274,6 +274,6 @@ Method Signature | Description | |
`activateFocus() => void` | Activates the focus state of the Text Field. Normally called in response to the input focus event. | ||
`deactivateFocus() => void` | Deactivates the focus state of the Text Field. Normally called in response to the input blur event. | ||
`setHelperTextContent(content: string) => void` | Sets the content of the helper text | ||
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. Trailing period. 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. nice find <needle_in_haystack_emoji> |
||
`updateOutline() => void` | Updates the focus outline for outlined text fields | ||
`notchOutline(activateNotch: boolean) => void` | Activates/deactivates the notched outline. | ||
|
||
`MDCTextFieldFoundation` supports multiple optional sub-elements: helper text and icon. The foundations of these sub-elements must be passed in as constructor arguments to `MDCTextFieldFoundation`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,7 @@ class MDCTextFieldFoundation extends MDCFoundation { | |
hasLabel: () => {}, | ||
getLabelWidth: () => {}, | ||
hasOutline: () => {}, | ||
updateOutlinePath: () => {}, | ||
notchOutline: () => {}, | ||
}); | ||
} | ||
|
||
|
@@ -135,6 +135,7 @@ class MDCTextFieldFoundation extends MDCFoundation { | |
// Ensure label does not collide with any pre-filled value. | ||
if (this.adapter_.hasLabel() && this.getValue()) { | ||
this.adapter_.floatLabel(this.shouldFloat); | ||
this.notchOutline(this.shouldFloat); | ||
} | ||
|
||
if (this.adapter_.isFocused()) { | ||
|
@@ -193,9 +194,10 @@ class MDCTextFieldFoundation extends MDCFoundation { | |
} | ||
|
||
/** | ||
* Updates the focus outline for outlined text fields. | ||
* Activates/deactivates the notched outline. | ||
* @param {boolean} activateNotch | ||
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: open notch? instead of activate? |
||
*/ | ||
updateOutline() { | ||
notchOutline(activateNotch) { | ||
if (!this.adapter_.hasOutline() || !this.adapter_.hasLabel()) { | ||
return; | ||
} | ||
|
@@ -204,7 +206,11 @@ class MDCTextFieldFoundation extends MDCFoundation { | |
const labelScale = isDense ? numbers.DENSE_LABEL_SCALE : numbers.LABEL_SCALE; | ||
const labelWidth = this.adapter_.getLabelWidth() * labelScale; | ||
const isRtl = this.adapter_.isRtl(); | ||
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. calculate all this labelWidth and isRTL within the if statement for opening the notch. |
||
this.adapter_.updateOutlinePath(labelWidth, isRtl); | ||
if (activateNotch) { | ||
this.adapter_.notchOutline(labelWidth, isRtl); | ||
} else { | ||
this.adapter_.notchOutline(0); | ||
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. setting the labelWidth = 0 in order to simulate "closing the notch" is unintuitive. Just add another method that explicitly closes the notch |
||
} | ||
} | ||
|
||
/** | ||
|
@@ -214,7 +220,7 @@ class MDCTextFieldFoundation extends MDCFoundation { | |
this.isFocused_ = true; | ||
this.styleFocused_(this.isFocused_); | ||
this.adapter_.activateLineRipple(); | ||
this.updateOutline(); | ||
this.notchOutline(this.shouldFloat); | ||
if (this.adapter_.hasLabel()) { | ||
this.adapter_.shakeLabel(this.shouldShake); | ||
this.adapter_.floatLabel(this.shouldFloat); | ||
|
@@ -260,6 +266,7 @@ class MDCTextFieldFoundation extends MDCFoundation { | |
if (this.adapter_.hasLabel()) { | ||
this.adapter_.shakeLabel(this.shouldShake); | ||
this.adapter_.floatLabel(this.shouldFloat); | ||
this.notchOutline(this.shouldFloat); | ||
} | ||
if (shouldRemoveLabelFloat) { | ||
this.receivedUserInput_ = false; | ||
|
@@ -283,6 +290,7 @@ class MDCTextFieldFoundation extends MDCFoundation { | |
if (this.adapter_.hasLabel()) { | ||
this.adapter_.shakeLabel(this.shouldShake); | ||
this.adapter_.floatLabel(this.shouldFloat); | ||
this.notchOutline(this.shouldFloat); | ||
} | ||
} | ||
|
||
|
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.
Could we change this so there are two methods
notch(notchWidth: number, isRtl: boolean) => void
and
closeNotch() => void