Skip to content

Fix TypeError: Argument 1 of Window.getComputedStyle does not implement interface Element. #15

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,32 @@ class InputTrigger extends Component {

this.handleTrigger = this.handleTrigger.bind(this);
this.resetState = this.resetState.bind(this);
this.element = this.props.elementRef;
this.findInput = this.findInput.bind(this);
}


componentDidMount() {
this.props.endTrigger(this.resetState);
this.element = this.findInput();
}

findInput() {
if (this.props.getElement) {
return this.props.getElement(this);
}
if (this.childElemnt instanceof Element && ['INPUT', 'TEXTAREA'].find(tag => tag === this.childElemnt.tagName)) {
return this.childElemnt;
}
const inputs = this.div.getElementsByTagName('input');
if (inputs.length) {
return inputs[0];
}
const textareas = this.div.getElementsByTagName('textarea');
if (textareas.length) {
return textareas[0];
}
return null;// Would like to warn, but lint disallowed console logs.
// console.warn('Multiple or no inputs detected', inputs);
}

handleTrigger(event) {
Expand Down Expand Up @@ -109,7 +130,7 @@ class InputTrigger extends Component {

render() {
const {
elementRef,
getElement,
children,
trigger,
onStart,
Expand All @@ -124,15 +145,18 @@ class InputTrigger extends Component {
role="textbox"
tabIndex={-1}
onKeyDown={this.handleTrigger}
ref={(el) => {
this.div = el;
}}
{...rest}
>
{
!elementRef
!getElement
? (
React.Children.map(this.props.children, child => (
React.cloneElement(child, {
ref: (element) => {
this.element = element;
this.childElemnt = element;
if (typeof child.ref === 'function') {
child.ref(element);
}
Expand Down Expand Up @@ -161,7 +185,7 @@ InputTrigger.propTypes = {
onType: PropTypes.func,
endTrigger: PropTypes.func,
children: PropTypes.element.isRequired,
elementRef: PropTypes.element,
getElement: PropTypes.func,
};

InputTrigger.defaultProps = {
Expand All @@ -175,7 +199,7 @@ InputTrigger.defaultProps = {
onCancel: () => {},
onType: () => {},
endTrigger: () => {},
elementRef: null,
getElement: undefined,
};

export default InputTrigger;