Skip to content

Commit

Permalink
fix(typescript): add types to disclosure and idPrefix (#17715)
Browse files Browse the repository at this point in the history
* fix(typescript): add types to disclosure and idPrefix

* fix(disclouse): test import

* Update packages/react/src/components/IdPrefix/index.tsx

Co-authored-by: Taylor Jones <tay1orjones@users.noreply.github.com>

* Update packages/react/src/components/IdPrefix/index.tsx

Co-authored-by: Taylor Jones <tay1orjones@users.noreply.github.com>

* fix(idPrefix): undefined

---------

Co-authored-by: Taylor Jones <tay1orjones@users.noreply.github.com>
  • Loading branch information
ariellalgilmore and tay1orjones authored Oct 11, 2024
1 parent 5be6c5b commit 107e572
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { render, screen } from '@testing-library/react';
import React from 'react';
import userEvent from '@testing-library/user-event';
import { useDisclosure } from '../index.js';
import { useDisclosure } from '../index';
import '@testing-library/jest-dom';

describe('useDisclosure', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@
*/

import PropTypes from 'prop-types';
import React from 'react';
import React, { PropsWithChildren, ReactNode } from 'react';
import { IdPrefixContext } from '../../internal/useIdPrefix';

function IdPrefix({ children, prefix }) {
type IdPrefixProps = {
children?: ReactNode;

/**
* The value used to prefix the auto-generated id placed on some DOM elements
*/
prefix?: string;
};

function IdPrefix({ children, prefix }: PropsWithChildren<IdPrefixProps>) {
return (
<IdPrefixContext.Provider value={prefix}>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

import React from 'react';

export const IdPrefixContext = React.createContext(null);
export const IdPrefixContext = React.createContext<string | null | undefined>(
null
);

export function useIdPrefix() {
return React.useContext(IdPrefixContext);
Expand Down

0 comments on commit 107e572

Please sign in to comment.