Add keyboardControl option and typo in readme
Browse files- index.html +2 -1
- readme.md +4 -3
- src/common/constants.js +1 -0
- src/index.js +4 -1
- types/index.d.ts +6 -0
index.html
CHANGED
@@ -278,6 +278,7 @@ driver.highlight({
|
|
278 |
nextBtnText: 'Next', // Next button text for this step
|
279 |
prevBtnText: 'Previous', // Previous button text for this step
|
280 |
showButtons: false, // Do not show control buttons in footer
|
|
|
281 |
scrollIntoViewOptions: {}, // We use `scrollIntoView()` when possible, pass here the options for it if you want any
|
282 |
onHighlightStarted: (Element) {}, // Called when element is about to be highlighted
|
283 |
onHighlighted: (Element) {}, // Called when element is fully highlighted
|
@@ -322,7 +323,7 @@ driver.hasPreviousStep(); // Checks if there is previous step to move to
|
|
322 |
// Gets the currently highlighted element on screen
|
323 |
const activeElement = driver.getHighlightedElement();
|
324 |
const lastActiveElement = driver.getLastHighlightedElement();
|
325 |
-
activeElement.
|
326 |
activeElement.hidePopover(); // Hide the popover
|
327 |
activeElement.showPopover(); // Show the popover
|
328 |
|
|
|
278 |
nextBtnText: 'Next', // Next button text for this step
|
279 |
prevBtnText: 'Previous', // Previous button text for this step
|
280 |
showButtons: false, // Do not show control buttons in footer
|
281 |
+
keyboardControl: true, // Allow controlling through keyboard (escape to close, arrow keys to move)
|
282 |
scrollIntoViewOptions: {}, // We use `scrollIntoView()` when possible, pass here the options for it if you want any
|
283 |
onHighlightStarted: (Element) {}, // Called when element is about to be highlighted
|
284 |
onHighlighted: (Element) {}, // Called when element is fully highlighted
|
|
|
323 |
// Gets the currently highlighted element on screen
|
324 |
const activeElement = driver.getHighlightedElement();
|
325 |
const lastActiveElement = driver.getLastHighlightedElement();
|
326 |
+
activeElement.getCalculatedPosition(); // Gets screen co-ordinates of the active element
|
327 |
activeElement.hidePopover(); // Hide the popover
|
328 |
activeElement.showPopover(); // Show the popover
|
329 |
|
readme.md
CHANGED
@@ -167,6 +167,7 @@ const driver = new Driver({
|
|
167 |
nextBtnText: 'Next', // Next button text for this step
|
168 |
prevBtnText: 'Previous', // Previous button text for this step
|
169 |
showButtons: false, // Do not show control buttons in footer
|
|
|
170 |
scrollIntoViewOptions: {}, // We use `scrollIntoView()` when possible, pass here the options for it if you want any
|
171 |
onHighlightStarted: (Element) {}, // Called when element is about to be highlighted
|
172 |
onHighlighted: (Element) {}, // Called when element is fully highlighted
|
@@ -258,9 +259,9 @@ const activeElement = driver.getHighlightedElement();
|
|
258 |
// Gets the last highlighted element, would be an instance of `/src/core/element.js`
|
259 |
const lastActiveElement = driver.getLastHighlightedElement();
|
260 |
|
261 |
-
activeElement.
|
262 |
-
activeElement.hidePopover();
|
263 |
-
activeElement.showPopover();
|
264 |
|
265 |
activeElement.getNode(); // Gets the DOM Element behind this element
|
266 |
```
|
|
|
167 |
nextBtnText: 'Next', // Next button text for this step
|
168 |
prevBtnText: 'Previous', // Previous button text for this step
|
169 |
showButtons: false, // Do not show control buttons in footer
|
170 |
+
keyboardControl: true, // Allow controlling through keyboard (escape to close, arrow keys to move)
|
171 |
scrollIntoViewOptions: {}, // We use `scrollIntoView()` when possible, pass here the options for it if you want any
|
172 |
onHighlightStarted: (Element) {}, // Called when element is about to be highlighted
|
173 |
onHighlighted: (Element) {}, // Called when element is fully highlighted
|
|
|
259 |
// Gets the last highlighted element, would be an instance of `/src/core/element.js`
|
260 |
const lastActiveElement = driver.getLastHighlightedElement();
|
261 |
|
262 |
+
activeElement.getCalculatedPosition(); // Gets screen co-ordinates of the active element
|
263 |
+
activeElement.hidePopover(); // Hide the popover
|
264 |
+
activeElement.showPopover(); // Show the popover
|
265 |
|
266 |
activeElement.getNode(); // Gets the DOM Element behind this element
|
267 |
```
|
src/common/constants.js
CHANGED
@@ -3,6 +3,7 @@ export const OVERLAY_PADDING = 10;
|
|
3 |
|
4 |
export const SHOULD_ANIMATE_OVERLAY = true;
|
5 |
export const SHOULD_OUTSIDE_CLICK_CLOSE = true;
|
|
|
6 |
export const SHOULD_OUTSIDE_CLICK_NEXT = false;
|
7 |
|
8 |
export const ESC_KEY_CODE = 27;
|
|
|
3 |
|
4 |
export const SHOULD_ANIMATE_OVERLAY = true;
|
5 |
export const SHOULD_OUTSIDE_CLICK_CLOSE = true;
|
6 |
+
export const ALLOW_KEYBOARD_CONTROL = true;
|
7 |
export const SHOULD_OUTSIDE_CLICK_NEXT = false;
|
8 |
|
9 |
export const ESC_KEY_CODE = 27;
|
src/index.js
CHANGED
@@ -15,6 +15,7 @@ import {
|
|
15 |
SHOULD_ANIMATE_OVERLAY,
|
16 |
SHOULD_OUTSIDE_CLICK_CLOSE,
|
17 |
SHOULD_OUTSIDE_CLICK_NEXT,
|
|
|
18 |
} from './common/constants';
|
19 |
import Stage from './core/stage';
|
20 |
import { isDomElement } from './common/utils';
|
@@ -33,6 +34,7 @@ export default class Driver {
|
|
33 |
padding: OVERLAY_PADDING, // Spacing around the element from the overlay
|
34 |
scrollIntoViewOptions: null, // Options to be passed to `scrollIntoView`
|
35 |
allowClose: SHOULD_OUTSIDE_CLICK_CLOSE, // Whether to close overlay on click outside the element
|
|
|
36 |
overlayClickNext: SHOULD_OUTSIDE_CLICK_NEXT, // Whether to move next on click outside the element
|
37 |
stageBackground: '#ffffff', // Background color for the stage
|
38 |
onHighlightStarted: () => { // When element is about to be highlighted
|
@@ -137,7 +139,8 @@ export default class Driver {
|
|
137 |
* @private
|
138 |
*/
|
139 |
onKeyUp(event) {
|
140 |
-
|
|
|
141 |
return;
|
142 |
}
|
143 |
|
|
|
15 |
SHOULD_ANIMATE_OVERLAY,
|
16 |
SHOULD_OUTSIDE_CLICK_CLOSE,
|
17 |
SHOULD_OUTSIDE_CLICK_NEXT,
|
18 |
+
ALLOW_KEYBOARD_CONTROL,
|
19 |
} from './common/constants';
|
20 |
import Stage from './core/stage';
|
21 |
import { isDomElement } from './common/utils';
|
|
|
34 |
padding: OVERLAY_PADDING, // Spacing around the element from the overlay
|
35 |
scrollIntoViewOptions: null, // Options to be passed to `scrollIntoView`
|
36 |
allowClose: SHOULD_OUTSIDE_CLICK_CLOSE, // Whether to close overlay on click outside the element
|
37 |
+
keyboardControl: ALLOW_KEYBOARD_CONTROL, // Whether to allow controlling through keyboard or not
|
38 |
overlayClickNext: SHOULD_OUTSIDE_CLICK_NEXT, // Whether to move next on click outside the element
|
39 |
stageBackground: '#ffffff', // Background color for the stage
|
40 |
onHighlightStarted: () => { // When element is about to be highlighted
|
|
|
139 |
* @private
|
140 |
*/
|
141 |
onKeyUp(event) {
|
142 |
+
// If driver is not active or keyboard control is disabled
|
143 |
+
if (!this.isActivated || !this.options.keyboardControl) {
|
144 |
return;
|
145 |
}
|
146 |
|
types/index.d.ts
CHANGED
@@ -645,6 +645,12 @@ declare module 'driver.js' {
|
|
645 |
*/
|
646 |
allowClose?: boolean,
|
647 |
|
|
|
|
|
|
|
|
|
|
|
|
|
648 |
/**
|
649 |
* Clicking outside the highlighted element should move next
|
650 |
* @default false
|
|
|
645 |
*/
|
646 |
allowClose?: boolean,
|
647 |
|
648 |
+
/**
|
649 |
+
* Whether to allow controlling steps through keyboard
|
650 |
+
* @default true
|
651 |
+
*/
|
652 |
+
keyboardControl?: boolean,
|
653 |
+
|
654 |
/**
|
655 |
* Clicking outside the highlighted element should move next
|
656 |
* @default false
|