forked from uber/baseweb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(select): calls provided onBlur function (uber#3148)
* fix(select): adds failing test * fix(Select): calls provided onBlur fn * fix(select): update snaps * test(vrt): update visual snapshots for 40b750c [skip ci] (uber#3149) Co-authored-by: UberOpenSourceBot <[email protected]> Co-authored-by: UberOpenSourceBot <[email protected]> Co-authored-by: UberOpenSourceBot <[email protected]>
- Loading branch information
1 parent
0792c09
commit b7399a0
Showing
7 changed files
with
110 additions
and
33 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,44 @@ | ||
/* | ||
Copyright (c) 2018-2020 Uber Technologies, Inc. | ||
This source code is licensed under the MIT license found in the | ||
LICENSE file in the root directory of this source tree. | ||
*/ | ||
/* global document */ | ||
/* eslint-env node */ | ||
/* eslint-disable flowtype/require-valid-file-annotation */ | ||
|
||
const {mount} = require('../../../e2e/helpers'); | ||
|
||
const SELECT_INPUT = 'div[data-baseweb="select"] input'; | ||
|
||
function getActiveTag(page) { | ||
return page.evaluate(() => { | ||
const el = document.activeElement; | ||
if (el) { | ||
return el.tagName; | ||
} | ||
}); | ||
} | ||
|
||
describe('select option click returns focus', () => { | ||
it('calls provided blur function when another element is focused', async () => { | ||
await mount(page, 'select-calls-provided-blur'); | ||
await page.waitFor(SELECT_INPUT); | ||
|
||
const input = await page.$(SELECT_INPUT); | ||
await input.click(); | ||
|
||
const beforeActiveTag = await getActiveTag(page); | ||
expect(beforeActiveTag).toBe('INPUT'); | ||
|
||
await page.keyboard.press('Tab'); | ||
|
||
const afterActiveTag = await getActiveTag(page); | ||
expect(afterActiveTag).toBe('BUTTON'); | ||
|
||
const p = await page.$('p'); | ||
const blurCount = await page.evaluate(el => el.textContent, p); | ||
expect(blurCount).toBe('1'); | ||
}); | ||
}); |
30 changes: 30 additions & 0 deletions
30
src/select/__tests__/select-calls-provided-blur.scenario.js
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,30 @@ | ||
/* | ||
Copyright (c) 2018-2020 Uber Technologies, Inc. | ||
This source code is licensed under the MIT license found in the | ||
LICENSE file in the root directory of this source tree. | ||
*/ | ||
// @flow | ||
|
||
import React from 'react'; | ||
|
||
import {StatefulSelect} from '../index.js'; | ||
|
||
export default function Scenario() { | ||
const [blurCount, setBlurCount] = React.useState(0); | ||
return ( | ||
<React.Fragment> | ||
<StatefulSelect | ||
closeOnSelect={false} | ||
onBlur={() => setBlurCount(prev => prev + 1)} | ||
options={[ | ||
{id: 'a', label: 'hey!'}, | ||
{id: 'b', label: 'are you listening?'}, | ||
{id: 'c', label: 'look at me!'}, | ||
]} | ||
/> | ||
<button>focus target</button> | ||
<p>{blurCount}</p> | ||
</React.Fragment> | ||
); | ||
} |
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
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.