forked from mui/base-ui
-
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.
- Loading branch information
1 parent
9c3111f
commit 1f51d47
Showing
6 changed files
with
107 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import * as React from 'react'; | ||
import { expect } from 'chai'; | ||
// import { spy } from 'sinon'; | ||
// import { act } from '@mui/internal-test-utils'; | ||
import { Toolbar } from '@base-ui-components/react/toolbar'; | ||
import { screen } from '@mui/internal-test-utils'; | ||
import { createRenderer, describeConformance } from '#test-utils'; | ||
import { NOOP } from '../../utils/noop'; | ||
import { ToolbarRootContext } from '../root/ToolbarRootContext'; | ||
import { CompositeRootContext } from '../../composite/root/CompositeRootContext'; | ||
|
||
const testCompositeContext = { | ||
highlightedIndex: 0, | ||
onHighlightedIndexChange: NOOP, | ||
}; | ||
|
||
const testToolbarContext: ToolbarRootContext = { | ||
disabled: false, | ||
orientation: 'horizontal', | ||
setItemMap: NOOP, | ||
}; | ||
|
||
describe('<Toolbar.Link />', () => { | ||
const { render } = createRenderer(); | ||
|
||
describeConformance(<Toolbar.Link />, () => ({ | ||
refInstanceof: window.HTMLAnchorElement, | ||
render: (node) => { | ||
return render( | ||
<ToolbarRootContext.Provider value={testToolbarContext}> | ||
<CompositeRootContext.Provider value={testCompositeContext}> | ||
{node} | ||
</CompositeRootContext.Provider> | ||
</ToolbarRootContext.Provider>, | ||
); | ||
}, | ||
})); | ||
|
||
describe('ARIA attributes', () => { | ||
it('renders an anchor', async () => { | ||
const { getByTestId } = await render( | ||
<Toolbar.Root> | ||
<Toolbar.Link data-testid="link" /> | ||
</Toolbar.Root>, | ||
); | ||
|
||
expect(getByTestId('button')).to.equal(screen.getByRole('button')); | ||
}); | ||
}); | ||
}); |
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,49 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import { useComponentRenderer } from '../../utils/useComponentRenderer'; | ||
import { BaseUIComponentProps } from '../../utils/types'; | ||
import { useButton } from '../../use-button'; | ||
import { CompositeItem } from '../../composite/item/CompositeItem'; | ||
import type { ToolbarOrientation } from '../root/ToolbarRoot'; | ||
import { useToolbarRootContext } from '../root/ToolbarRootContext'; | ||
|
||
const ToolbarLink = React.forwardRef(function ToolbarLink( | ||
props: ToolbarLink.Props, | ||
forwardedRef: React.ForwardedRef<HTMLAnchorElement>, | ||
) { | ||
const { className, render, ...otherProps } = props; | ||
|
||
const { orientation } = useToolbarRootContext(); | ||
|
||
const { getButtonProps } = useButton({ | ||
buttonRef: forwardedRef, | ||
elementName: 'a', | ||
}); | ||
|
||
const state: ToolbarLink.State = React.useMemo( | ||
() => ({ | ||
orientation, | ||
}), | ||
[orientation], | ||
); | ||
|
||
const { renderElement } = useComponentRenderer({ | ||
propGetter: getButtonProps, | ||
render: render ?? 'a', | ||
state, | ||
className, | ||
extraProps: otherProps, | ||
}); | ||
|
||
return <CompositeItem render={renderElement()} />; | ||
}); | ||
|
||
export namespace ToolbarLink { | ||
export interface State { | ||
orientation: ToolbarOrientation; | ||
} | ||
|
||
export interface Props extends BaseUIComponentProps<'a', State> {} | ||
} | ||
|
||
export { ToolbarLink }; |
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