Skip to content

Commit e5e8be1

Browse files
committed
MAGEDOC-3441: Edit Knockout bindings topic
- Update bindings topic
1 parent e9df394 commit e5e8be1

File tree

1 file changed

+53
-26
lines changed

1 file changed

+53
-26
lines changed

docs/reference/knockout-bindings.md

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,83 @@
22

33
## Summary
44

5-
As part of the Page Builder application, we provide new Knockout bindings you can use in your custom content types:
5+
As part of the Page Builder application, we provide a number of new Knockout bindings to add additional functionality to certain content types through Knockouts binding syntax.
66

7-
| Name | Description | Usage |
8-
| -------------- | -------------------------------------------------------------- | ------------------------------------- |
9-
| sortable | Enables sorting the children of a bound element. | \<div data-bind="sortable: {}"></div> |
10-
| draggable | Enables draggable functionality on DOM elements. | \<div data-bind="draggable: {}"></div> |
11-
| live-edit | Enables editing text directly from the Admin stage. | \<div data-bind="liveEdit: {}"></div> |
12-
| focus | Enables default focus on DOM elements. | \<div data-bind="hasFocusNoScroll: $parent.focusedSlide() === $index()"></div> |
7+
| Binding Name | Description |
8+
| -------------- | -------------------------------------------------------------- |
9+
| `sortable` | Enables sorting the children of a bound element. We use this within container content types such as the root container, row and columns to enable drag and drop capabilities on their children content types. This can be used for easy access to the jQuery UI sortable functionality within your module. |
10+
| `draggable` | Enables draggable functionality on DOM elements. We use this to enable the content types in the left menu to be dragged and dropped into containers on the stage. |
11+
| `liveEdit` | Enables basic live text editing on the stage, this also supports displaying additional items within the live edit UI for easier modification. You can read more about how to use live edit within our [How to add a custom Toolbar](../how-to/how-to-add-custom-toolbar.md) guide. |
12+
| `hasFocusNoScroll` | Enables an element to use Knockout `hasFocus` binding without it causing the browser to scroll to the element, we use this within Slider to ensure the correct slide is focused but we do not want to scroll this into view always. |
13+
{:style="table-layout:auto"}
1314

14-
### Sortable binding
15+
### `sortable` binding
1516

1617
```shell
17-
app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/binding/sortable.ts
18+
view/adminhtml/web/ts/js/binding/sortable.ts
1819
```
1920

20-
The options in this binding are passed to the jQuery UI sortable instance. All options and their descriptions are available on the jQuery UI site: http://api.jqueryui.com/sortable/.
21+
This binding serves as an interface for jQuery UI Sortable.
2122

2223
Within Page Builder, we use the `sortable` binding to pass preview-component options to the drag-and-drop binding. We bind multiple options and events to the `sortable` instance so we can correctly respond to user actions when dragging and dropping content. Configuration and usage of the `sortable` binding can be seen in the Preview component:
2324

24-
Example Configuration:
25+
**Configuration:**
2526

26-
```shell
27-
app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/content-type/preview.ts
28-
```
27+
Please see the options listed on jQuery UI's Sortable API page: http://api.jqueryui.com/sortable/
2928

30-
Example Usage:
29+
**Usage:**
3130

32-
```shell
33-
app/code/Magento/PageBuilder/view/adminhtml/web/template/content-type/preview.html
31+
```html
32+
<div data-bind="sortable: getSortableOptions()" />
3433
```
34+
_As jQuery UI can have callback functions we recommend providing this configuration from a function within your Knockout view model._
3535

36-
### Draggable binding
36+
### `draggable` binding
3737

3838
```shell
39-
app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/binding/draggable.ts
39+
view/adminhtml/web/ts/js/binding/draggable.ts
4040
```
4141

42-
The options provided in this binding are passed to the jQuery UI draggable instance. All options and their descriptions are available on the jQuery UI site: http://api.jqueryui.com/draggable/.
42+
This binding serves as an interface for jQuery UI Draggable.
4343

4444
Within Page Builder, we use this binding for the left panel's content types. The configuration and usage of the `draggable` binding can be seen in the Panel component:
4545

46-
Example Configuration:
46+
**Configuration:**
4747

48-
```shell
49-
app/code/Magento/PageBuilder/view/adminhtml/web/ts/js/panel.ts
48+
Please see the options listed on jQuery UI's Sortable API page: http://api.jqueryui.com/draggable/
49+
50+
**Usage:**
51+
52+
```html
53+
<div data-bind="draggable: getDraggableOptions()" />
5054
```
55+
_As jQuery UI can have callback functions we recommend providing this configuration from a function within your Knockout view model._
5156

52-
Example Usage:
57+
### `liveEdit` binding
5358

54-
```shell
55-
app/code/Magento/PageBuilder/view/adminhtml/web/template/panel.html
59+
This binding provides basic text live editing functionality to the current element, it does this by adding the `contenteditable` functionality to the bound element.
60+
61+
**Configuration:**
62+
63+
| Name | Description |
64+
| -------------- | -------------------------------------------------------------- |
65+
| `field` | The field name from the UI component form which you wish the live edit instance to edit. |
66+
| `placeholder` | _Optional_. A placeholder to display if there is no data for this field.
67+
| `selectAll` | _Optional_. Selects all text on focus within the live edit field. We use this within tabs. |
68+
{:style="table-layout:auto"}
69+
70+
**Usage:**
71+
```html
72+
<div data-bind="liveEdit: { field: 'field', placeholder: $t('Placeholder'), selectAll: true }" />
5673
```
5774

75+
### `hasFocusNoScroll` binding
76+
77+
This binding enables the functionality of Knockout's [hasFocus](https://knockoutjs.com/documentation/hasfocus-binding.html) binding whilst removing the automatic scrolling that will occur when focusing an element within the browser.
78+
79+
The binding has no configuration and must be passed an observable with a boolean value.
80+
81+
**Usage:**
82+
```html
83+
<div data-bind="hasFocusNoScroll: anObservable" />
84+
```

0 commit comments

Comments
 (0)