Skip to content

Commit

Permalink
Make blinking input carets transparent to avoid flakiness (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
oblador committed Jun 3, 2020
1 parent 0963842 commit 8f5f5fe
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions examples/react/src/FocusedInput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';

const FocusedInput = () => <input type="text" autoFocus />;

export default FocusedInput;
3 changes: 3 additions & 0 deletions examples/react/src/stories/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import NonIntViewport from '../NonIntViewport';
import FetchComponent from '../FetchComponent';
import ZeroHeightWithPadding from '../ZeroHeightWithPadding';
import Hover from '../Hover';
import FocusedInput from '../FocusedInput';

storiesOf('Welcome', module).lokiSkip('to Storybook', () => (
<Welcome showApp={linkTo('Button')} />
Expand Down Expand Up @@ -73,3 +74,5 @@ storiesOf('Zero height', module).add('with padding', () => (
));

storiesOf('Hover', module).add('default', () => <Hover />);

storiesOf('FocusedInput', module).add('default', () => <FocusedInput />);
16 changes: 16 additions & 0 deletions packages/browser/src/disable-input-caret.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const disableInputCaret = window => {
const DISABLE_INPUT_CARET_STYLE = `
* {
caret-color: transparent !important;
}
`;

// Make blinking input carets transparent to avoid flakiness.
window.document.addEventListener('DOMContentLoaded', () => {
const styleElement = window.document.createElement('style');
window.document.documentElement.appendChild(styleElement);
styleElement.sheet.insertRule(DISABLE_INPUT_CARET_STYLE);
});
};

module.exports = disableInputCaret;
2 changes: 2 additions & 0 deletions packages/browser/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const addLokiSessionMarker = require('./add-loki-session-marker');
const awaitLokiReady = require('./await-loki-ready');
const createStorybookConfigurator = require('./configure-storybook');
const disableAnimations = require('./disable-animations');
const disableInputCaret = require('./disable-input-caret');
const disablePointerEvents = require('./disable-pointer-events');
const getSelectorBoxSize = require('./get-selector-box-size');
const getStories = require('./get-stories');
Expand All @@ -11,6 +12,7 @@ module.exports = {
awaitLokiReady,
createStorybookConfigurator,
disableAnimations,
disableInputCaret,
disablePointerEvents,
getSelectorBoxSize,
getStories,
Expand Down
2 changes: 2 additions & 0 deletions packages/target-chrome-core/src/create-chrome-target.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const debug = require('debug')('loki:chrome');
const {
disableAnimations,
disableInputCaret,
disablePointerEvents,
getSelectorBoxSize,
getStories,
Expand Down Expand Up @@ -164,6 +165,7 @@ function createChromeTarget(
await evaluateOnNewDocument(`(${disableAnimations})(window);`);
}
await evaluateOnNewDocument(`(${disablePointerEvents})(window);`);
await evaluateOnNewDocument(`(${disableInputCaret})(window);`);

debug(`Navigating to ${url}`);
await Promise.all([Page.navigate({ url }), awaitRequestsFinished()]);
Expand Down

0 comments on commit 8f5f5fe

Please sign in to comment.