-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(components): add
Perceivable
to support aria-disabled
for RAC (
#1488) * feat(components): add `Perceivable` to support `aria-disabled` for RAC * fix: scope with data attribute
- Loading branch information
Showing
10 changed files
with
135 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@launchpad-ui/components": patch | ||
--- | ||
|
||
Add `Perceivable` to support `aria-disabled` for RAC |
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,38 @@ | ||
import { describe, expect, it, vi } from 'vitest'; | ||
|
||
import { render, screen, userEvent, waitFor } from '../../../test/utils'; | ||
import { Button, Perceivable, Tooltip, TooltipTrigger } from '../src'; | ||
|
||
describe('Perceivable', () => { | ||
it('sets aria-disabled', async () => { | ||
render( | ||
<Perceivable> | ||
<TooltipTrigger> | ||
<Button>Button</Button> | ||
<Tooltip>Message</Tooltip> | ||
</TooltipTrigger> | ||
</Perceivable>, | ||
); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByRole('button', { hidden: true })).toHaveAttribute('aria-disabled', 'true'); | ||
}); | ||
}); | ||
|
||
it('prevents events', async () => { | ||
const spy = vi.fn(); | ||
const user = userEvent.setup(); | ||
|
||
render( | ||
<Perceivable> | ||
<TooltipTrigger> | ||
<Button onPress={spy}>Button</Button> | ||
<Tooltip>Message</Tooltip> | ||
</TooltipTrigger> | ||
</Perceivable>, | ||
); | ||
|
||
await user.click(screen.getByRole('button', { hidden: true })); | ||
expect(spy).toHaveBeenCalledTimes(0); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { KeyboardEvents, PressEvents } from '@react-types/shared'; | ||
import type { ReactNode } from 'react'; | ||
|
||
import { FocusableProvider } from '@react-aria/focus'; | ||
import { createContext } from 'react'; | ||
import { Provider } from 'react-aria-components'; | ||
|
||
interface InteractionProps extends KeyboardEvents, PressEvents {} | ||
|
||
interface PerceivableProps { | ||
children: ReactNode; | ||
} | ||
|
||
const PerceivableContext = createContext<InteractionProps>({}); | ||
|
||
const Perceivable = ({ children }: PerceivableProps) => { | ||
const props = { | ||
onPress: undefined, | ||
onPressStart: undefined, | ||
onPressEnd: undefined, | ||
onPressChange: undefined, | ||
onPressUp: undefined, | ||
onKeyDown: undefined, | ||
onKeyUp: undefined, | ||
onClick: undefined, | ||
href: undefined, | ||
}; | ||
|
||
return ( | ||
<Provider values={[[PerceivableContext, { ...props }]]}> | ||
<FocusableProvider aria-disabled="true" data-lp=""> | ||
{children} | ||
</FocusableProvider> | ||
</Provider> | ||
); | ||
}; | ||
|
||
export { Perceivable, PerceivableContext }; | ||
export type { PerceivableProps }; |
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 |
---|---|---|
|
@@ -77,3 +77,8 @@ | |
cursor: not-allowed; | ||
} | ||
} | ||
|
||
:global([data-lp][aria-disabled='true']) { | ||
opacity: 0.64; | ||
cursor: default; | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.