Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify content density handling with Fiori Launchpad in more details #172

Merged
merged 17 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/03_Get-Started/step-36-content-density-d935dbf.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ In this step of our Walkthrough tutorial, we adjust the content density based on



**The content density is compact on desktop devices and cozy on touch-enabled devices**
**The default content density is cozy on touch devices (smartphones, tablets and computers with a touch screen) and compact on devices without a touch screen. Note that Fiori Launchpad sets cozy content density on phones and tablets as mandatory and may override it on other computers according to the application manifest and the user preference.**
ulasenka marked this conversation as resolved.
Show resolved Hide resolved

![The graphic has an explanatory text.](images/UI5_Walkthrough_Step_36_f216b13.png "The content density is compact on desktop devices and cozy on touch-enabled
devices")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ You can view all files at [OpenUI5 TypeScript Walkthrough - Step 36: Content Den

To prepare the content density feature we add a helper method `getContentDensityClass` to the app component. SAPUI5 controls can be displayed in multiple sizes, for example in a `compact` size that is optimized for desktop and non-touch devices, and in a `cozy` mode that is optimized for touch interaction. The controls look for a specific CSS class in the HTML structure of the application to adjust their size.

This helper method queries the `Device` API directly for touch support of the client and returns the CSS class `sapUiSizeCompact` if touch interaction is not supported and `sapUiSizeCozy` for all other cases. We will use it throughout the application coding to set the proper content density CSS class.
This helper method checks if the content density is already set by the shell. If not, it queries the `Device` API directly for touch support of the client and returns the CSS class `sapUiSizeCompact` if touch interaction is not supported and `sapUiSizeCozy` for all other cases. We will use it throughout the application coding to set the proper content density CSS class.
KlattG marked this conversation as resolved.
Show resolved Hide resolved

```js
import UIComponent from "sap/ui/core/UIComponent";
Expand All @@ -47,6 +47,12 @@ export default class Component extends UIComponent {
...
};
getContentDensityClass(): string {
// if the Fiori Launchpad has already set the content density class according to its logic, don't override it
KlattG marked this conversation as resolved.
Show resolved Hide resolved
const classList = document.body.classList;
if (classList.contains("sapUiSizeCozy") || classList.contains("sapUiSizeCompact")) {
return "";
}
// if the application runs standalone, use cozy on touch devices
return Device.support.touch ? "sapUiSizeCozy" : "sapUiSizeCompact";
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ var btn = new Button({

## Using Density Classes in the SAP Fiori launchpad

The SAP Fiori launchpad \(FLP\) optionally reads the supported content densities from the app descriptor \(`manifest.json`\) and - if available - sets the appropriate content density class on the `<body>` tag. On devices with mouse and touch support, the FLP also allows the desired content density to be configured by the user. To avoid situations where an application and the FLP write different content density classes, we recommend using the following logic within all applications that are intended to be used inside the FLP:
The SAP Fiori launchpad \(FLP\) optionally reads the supported content densities from the app descriptor \(`manifest.json`\) and - if available - sets the appropriate content density class on the `<body>` tag. On desktop devices, the FLP also allows the desired content density to be configured by the user. To avoid situations where an application and the FLP write different content density classes, we recommend using the following logic within all applications that are intended to be used inside the FLP:

```js

Expand Down
Loading