Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: General refactors on Composite components (#604)
- Loading branch information
Showing
79 changed files
with
5,420 additions
and
3,007 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
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
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 |
---|---|---|
|
@@ -35,3 +35,4 @@ | |
/cx | ||
/createOnKeyDown | ||
/closest | ||
/applyState |
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
28 changes: 28 additions & 0 deletions
28
packages/reakit-utils/src/__tests__/hasFocusWithin-test.tsx
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,28 @@ | ||
import * as React from "react"; | ||
import { render, focus } from "reakit-test-utils"; | ||
import { hasFocusWithin } from "../hasFocusWithin"; | ||
|
||
test("hasFocusWithin", () => { | ||
const { getByLabelText: $ } = render( | ||
<> | ||
<div aria-label="item1"> | ||
<button aria-label="item1-1" /> | ||
</div> | ||
<button aria-label="item2" /> | ||
{/* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */} | ||
<div aria-label="item3" tabIndex={0} aria-activedescendant="item3-1"> | ||
<div aria-label="item3-1" id="item3-1" /> | ||
</div> | ||
</> | ||
); | ||
expect(hasFocusWithin($("item1"))).toBe(false); | ||
focus($("item1-1")); | ||
expect(hasFocusWithin($("item1"))).toBe(true); | ||
expect(hasFocusWithin($("item2"))).toBe(false); | ||
focus($("item2")); | ||
expect(hasFocusWithin($("item2"))).toBe(true); | ||
expect(hasFocusWithin($("item3-1"))).toBe(false); | ||
focus($("item3")); | ||
expect(hasFocusWithin($("item3"))).toBe(true); | ||
expect(hasFocusWithin($("item3-1"))).toBe(true); | ||
}); |
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,27 @@ | ||
import * as React from "react"; | ||
|
||
function isUpdater<T>( | ||
argument: React.SetStateAction<T> | ||
): argument is React.ReducerWithoutAction<T> { | ||
return typeof argument === "function"; | ||
} | ||
|
||
/** | ||
* Receives a `setState` argument and calls it with `currentValue` if it's a | ||
* function. Otherwise return the argument as the new value. | ||
* | ||
* @example | ||
* import { applyState } from "reakit-utils"; | ||
* | ||
* applyState(value => value + 1, 1); // 2 | ||
* applyState(2, 1); // 2 | ||
*/ | ||
export function applyState<T>( | ||
argument: React.SetStateAction<T>, | ||
currentValue: T | ||
) { | ||
if (isUpdater(argument)) { | ||
return argument(currentValue); | ||
} | ||
return argument; | ||
} |
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
Oops, something went wrong.