-
-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added and implemented Focus and FocusBySelector methods * Added e2e tests * Updated CHANGELOG * Fixed linting errors
- Loading branch information
Showing
12 changed files
with
154 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import random from "../../../utils/random.js"; | ||
|
||
const e = React.createElement; | ||
|
||
export default class FocusableComponent extends React.PureComponent { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
show: props.show === true | ||
}; | ||
} | ||
|
||
toggle(show) { | ||
let timeout = 500; | ||
|
||
if (this.props.randomTimeout) { | ||
timeout = random(); | ||
} | ||
|
||
setTimeout(() => { | ||
this.setState({ | ||
show: show | ||
}) | ||
}, timeout) | ||
} | ||
|
||
handleFocus() { | ||
this.toggle(true); | ||
} | ||
|
||
handleBlur() { | ||
this.toggle(false); | ||
} | ||
|
||
render() { | ||
const btnId = `${this.props.id}-input`; | ||
const contentId = `${this.props.id}-content`; | ||
const classNames = ["alert"]; | ||
|
||
if (this.state.show === true) { | ||
classNames.push("alert-success"); | ||
} | ||
|
||
return e("div", {className: "card focusable"}, [ | ||
e("div", { className: "card-header"}, [ | ||
e("div", { classNames: "form-group" }, [ | ||
e("input", { | ||
id: btnId, | ||
className: "form-control", | ||
onFocus: this.handleFocus.bind(this), | ||
onBlur: this.handleBlur.bind(this) | ||
|
||
}) | ||
]) | ||
]), | ||
e("div", { className: "card-body"}, [ | ||
e("div", { id: contentId, className: classNames.join(" ")}, [ | ||
e("p", null, [ | ||
"Lorem ipsum dolor sit amet." | ||
]) | ||
]) | ||
]) | ||
]); | ||
} | ||
} |
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,8 @@ | ||
LET url = @dynamic + "/#/events" | ||
LET page = DOCUMENT(url, true) | ||
|
||
FOCUS(page, "#focus-input") | ||
|
||
WAIT_CLASS(page, "#focus-content", "alert-success") | ||
|
||
RETURN "" |
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,10 @@ | ||
LET url = @dynamic + "/#/events" | ||
LET page = DOCUMENT(url, true) | ||
|
||
LET input = ELEMENT(page, "#focus-input") | ||
|
||
FOCUS(input) | ||
|
||
WAIT_CLASS(page, "#focus-content", "alert-success") | ||
|
||
RETURN "" |
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
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,38 @@ | ||
package html | ||
|
||
import ( | ||
"context" | ||
"github.com/MontFerret/ferret/pkg/drivers" | ||
"github.com/MontFerret/ferret/pkg/runtime/core" | ||
"github.com/MontFerret/ferret/pkg/runtime/values" | ||
) | ||
|
||
// FOCUS Calls focus on the element. | ||
// @param target (HTMLPage | HTMLDocument | HTMLElement) - Target node. | ||
// @param selector (String, optional) - Optional CSS selector. Required when target is HTMLPage or HTMLDocument. | ||
func Focus(ctx context.Context, args ...core.Value) (core.Value, error) { | ||
err := core.ValidateArgs(args, 1, 2) | ||
|
||
if err != nil { | ||
return values.None, err | ||
} | ||
|
||
// Document with selector | ||
if len(args) == 2 { | ||
doc, err := drivers.ToDocument(args[0]) | ||
|
||
if err != nil { | ||
return values.None, err | ||
} | ||
|
||
return values.None, doc.FocusBySelector(ctx, values.ToString(args[1])) | ||
} | ||
|
||
el, err := drivers.ToElement(args[0]) | ||
|
||
if err != nil { | ||
return values.None, err | ||
} | ||
|
||
return values.None, el.Focus(ctx) | ||
} |
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