Skip to content

Commit

Permalink
fix(CompositeBar): fix stucking multipleTooltip (#117)
Browse files Browse the repository at this point in the history
* fix(CompositeBar): fix stucking multipleTooltip

* fix(storybook): add focus on story iframe
  • Loading branch information
Lunory authored Oct 1, 2023
1 parent 177cfd5 commit be6534e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
11 changes: 11 additions & 0 deletions .storybook/focus-addon/register.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {addons, } from '@storybook/addons';

addons.register('initialFocus', () => {
addons.getChannel().on('currentStoryWasSet', () => focusIframe());
})

const focusIframe = () => {
const previewIframe: HTMLInputElement | null = document.querySelector('#storybook-preview-iframe');

previewIframe?.focus?.();
}
3 changes: 2 additions & 1 deletion .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const config: StorybookConfig = {
'@storybook/addon-interactions',
'@storybook/preset-scss',
'storybook-preset-inline-svg',
'./theme-addon/register.tsx'
'./theme-addon/register.tsx',
'./focus-addon/register.tsx'
],
framework: {
name: '@storybook/react-webpack5',
Expand Down
8 changes: 4 additions & 4 deletions src/components/CompositeBar/CompositeBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const CompositeBarView: FC<CompositeBarViewProps> = ({

const onMouseEnterByIndex = useCallback(
(itemIndex) => () => {
if (multipleTooltip) {
if (multipleTooltip && document.hasFocus()) {
let multipleTooltipActiveValue = multipleTooltipActive;
if (!multipleTooltipActive && itemIndex !== lastClickedItemIndex) {
multipleTooltipActiveValue = true;
Expand All @@ -139,7 +139,7 @@ const CompositeBarView: FC<CompositeBarViewProps> = ({
);

const onMouseLeave = useCallback(() => {
if (compact) {
if (compact && document.hasFocus()) {
ref.current?.activateItem(undefined as unknown as number);
if (
multipleTooltip &&
Expand Down Expand Up @@ -220,9 +220,9 @@ const CompositeBarView: FC<CompositeBarViewProps> = ({
}}
/>
</div>
{type === 'menu' && (
{type === 'menu' && multipleTooltip && (
<MultipleTooltip
open={compact && multipleTooltip && multipleTooltipActive}
open={compact && multipleTooltipActive}
anchorRef={tooltipRef}
placement={['right-start']}
items={items}
Expand Down

0 comments on commit be6534e

Please sign in to comment.