-
Notifications
You must be signed in to change notification settings - Fork 26.2k
fix(platform-server): add styles to elements correctly #22527
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
Conversation
|
const styleMap = {}; | ||
const styleAttribute = element.getAttribute('style'); | ||
if (styleAttribute) { | ||
const styleList = styleAttribute.split(/;+/g); |
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.
nit: what about /(\s*;\s*)+/g
here ?
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.
oh would not work either so maybe
1- split on /;+/g
2- trim()
the parts
3- ignore empty parts
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 changed the logic, let me know if that's what you had in mind
@vicb changed commit message and opened a new issue |
@vicb any updates on merging this PR? |
if (styleAttribute) { | ||
const styleList = styleAttribute.split(/;+/g); | ||
for (let i = 0; i < styleList.length; i++) { | ||
if (styleList[i].length > 0) { |
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.
trim
ing before checking the length would probably make more sense ?
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.
Fixed
if (!style) { | ||
continue; | ||
} | ||
const colon = style.indexOf(':'); |
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.
nit colon -> colonIndex
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.
Fixed
if (colon === -1) { | ||
throw new Error(`Invalid CSS style: ${style}`); | ||
} | ||
(styleMap as any)[style.substr(0, colon).trim()] = style.substr(colon + 1).trim(); |
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.
nit: extract const name = style.substr(0, colon).trim();
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.
there should be as any
needed here
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.
Fixed
@@ -135,17 +135,53 @@ export class DominoAdapter extends BrowserDomAdapter { | |||
return href; | |||
} | |||
|
|||
/** @internal */ | |||
_readStyleAttribute(element: any) { | |||
const styleMap = {}; |
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.
const styleMap: {[name: string]: string} = {}
and then remove un-needed "as any"
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.
Fixed
@@ -135,17 +135,53 @@ export class DominoAdapter extends BrowserDomAdapter { | |||
return href; | |||
} | |||
|
|||
/** @internal */ | |||
_readStyleAttribute(element: any) { |
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.
add return type
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.
Fixed
setStyle(element: any, styleName: string, styleValue?: string|null) { | ||
styleName = styleName.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); | ||
element.style[styleName] = styleValue; | ||
const styleMap = this._readStyleAttribute(element); | ||
(styleMap as any)[styleName] = styleValue; |
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.
no need for any if types are specified upstream
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.
Fixed
} | ||
getStyle(element: any, styleName: string): string { | ||
return element.style[styleName] || element.style.getPropertyValue(styleName); | ||
const styleMap = this._readStyleAttribute(element); | ||
return styleMap.hasOwnProperty(styleName) ? (styleMap as any)[styleName] : ''; |
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.
no need for as any
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.
Fixed
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.
a few nits but LGTM otherwise.
Thanks and sorry for the delay in reviewing
|
fb9f9ec
to
7be1a4a
Compare
Should be |
setStyle(element: any, styleName: string, styleValue?: string|null) { | ||
styleName = styleName.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); | ||
element.style[styleName] = styleValue; | ||
const styleMap = this._readStyleAttribute(element); | ||
styleMap[styleName] = styleValue + ''; |
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.
do we really want "undefined"
as a possible value ?
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.
Fixed
} | ||
getStyle(element: any, styleName: string): string { | ||
return element.style[styleName] || element.style.getPropertyValue(styleName); | ||
const styleMap = this._readStyleAttribute(element); | ||
return styleMap.hasOwnProperty(styleName) ? styleMap[styleName] : ''; |
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.
return styleMap[styleName] || '';
?
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.
Fixed
* Partially reverts angular#22263 due to lack of total spec compliance on the server * Maintains the camel-case styles fix PR Close angular#22527
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
on the server
Fixes #22536