forked from TryGhost/Ghost
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rendered member login form in Shadow DOM instead of an iframe
refs TryGhost#16960 Attempted to fix the issue of password managers not autofilling in the login form. Shadow DOM would allow to preserve the style encapsulation, while not requiring too many changes. Unfortunately, it did not work.
- Loading branch information
1 parent
da919c8
commit ae20e51
Showing
5 changed files
with
68 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import {Component} from 'react'; | ||
import {createPortal} from 'react-dom'; | ||
|
||
export default class ShadowRoot extends Component { | ||
static isSupported() { | ||
return ( | ||
typeof window !== 'undefined' && | ||
window.Element && | ||
window.Element.prototype.hasOwnProperty('attachShadow') | ||
); | ||
} | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { ready: false }; | ||
} | ||
|
||
componentDidMount() { | ||
this.shadowRoot = this.node.attachShadow({ | ||
mode: 'open', | ||
}); | ||
|
||
this.setState({ ready: true }); | ||
} | ||
|
||
render() { | ||
const { | ||
children, | ||
head, | ||
style = {}, | ||
dataTestId = '', | ||
...rest | ||
} = this.props; | ||
return ( | ||
<div | ||
data-testid={dataTestId} | ||
ref={(node) => (this.node = node)} | ||
style={style} | ||
{...rest} | ||
> | ||
{this.state.ready && | ||
createPortal( | ||
<> | ||
{head} | ||
{children} | ||
</>, | ||
this.shadowRoot | ||
)} | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters