Skip to content

Commit

Permalink
[Discover] fix: set smaller max width for mobile devices (#199798)
Browse files Browse the repository at this point in the history
(cherry picked from commit fbd06a3)
  • Loading branch information
akowalska622 committed Nov 14, 2024
1 parent 55ef74d commit 9ee01de
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ import { calculateWidthFromEntries } from '@kbn/calculate-width-from-char-count'
import { DataViewListItemEnhanced } from './dataview_list';

const MIN_WIDTH = 300;
const MAX_MOBILE_WIDTH = 350;

export const changeDataViewStyles = ({
fullWidth,
dataViewsList,
theme,
isMobile,
}: {
fullWidth?: boolean;
dataViewsList: DataViewListItemEnhanced[];
theme: EuiThemeComputed;
isMobile: boolean;
}) => {
return {
trigger: {
Expand All @@ -30,7 +33,10 @@ export const changeDataViewStyles = ({
borderBottomLeftRadius: 0,
},
popoverContent: {
width: calculateWidthFromEntries(dataViewsList, ['name', 'id'], { minWidth: MIN_WIDTH }),
width: calculateWidthFromEntries(dataViewsList, ['name', 'id'], {
minWidth: MIN_WIDTH,
...(isMobile && { maxWidth: MAX_MOBILE_WIDTH }),
}),
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
EuiContextMenuItem,
useEuiTheme,
useGeneratedHtmlId,
useIsWithinBreakpoints,
EuiIcon,
EuiText,
EuiContextMenuPanelProps,
Expand Down Expand Up @@ -68,10 +69,13 @@ export function ChangeDataView({
const kibana = useKibana<IUnifiedSearchPluginServices>();
const { application, data, dataViews, dataViewEditor } = kibana.services;

const isMobile = useIsWithinBreakpoints(['xs']);

const styles = changeDataViewStyles({
fullWidth: trigger.fullWidth,
dataViewsList,
theme: euiTheme,
isMobile,
});

// Create a reusable id to ensure search input is the first focused item in the popover even though it's not the first item
Expand Down

0 comments on commit 9ee01de

Please sign in to comment.