Skip to content

Commit

Permalink
Tooltip placement override (deephaven#1909)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Apr 2, 2024
1 parent 4ae068b commit ac0d476
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions packages/components/src/spectrum/utils/itemUtils.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,9 @@ describe('normalizeTooltipOptions', () => {
const actual = normalizeTooltipOptions(options);
expect(actual).toEqual(expected);
});

it('should allow overriding default placement', () => {
const actual = normalizeTooltipOptions(true, 'top');
expect(actual).toEqual({ placement: 'top' });
});
});
9 changes: 6 additions & 3 deletions packages/components/src/spectrum/utils/itemUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,18 +288,21 @@ export function normalizeItemList<TItemOrSection extends ItemOrSection>(

/**
* Returns a TooltipOptions object or null if options is false or null.
* @param options
* @param options Tooltip options
* @param placement Default placement for the tooltip if `options` is set
* explicitly to `true`
* @returns TooltipOptions or null
*/
export function normalizeTooltipOptions(
options?: boolean | TooltipOptions | null
options?: boolean | TooltipOptions | null,
placement: TooltipOptions['placement'] = 'right'
): TooltipOptions | null {
if (options == null || options === false) {
return null;
}

if (options === true) {
return { placement: 'right' };
return { placement };
}

return options;
Expand Down

0 comments on commit ac0d476

Please sign in to comment.