Skip to content

Dialog ​

Declarative modal dialog. Title + content + confirm / cancel buttons, with the scrim and the card rendered on separate layers.

Spec source: lh-ui-core/specs/dialog.json · Golden cases: lh-ui-core/cases/dialog.json (12 cases, translated into hypium tests)

Declarative visibility

When visible is false, nothing is rendered. After confirm / cancel the component fires onClose, and the host sets visible back to false (isomorphic to react's open / onClose). The component must be mounted as the last child of the page's Stack; elevation is carried by the zIndex tokens.

Basic usage ​

9:41Dialog basics

Confirm deletion

Deletion is irreversible. Are you sure you want to delete this record?

HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render

typescript
LhDialog({
  visible: this.dialogVisible,
  title: 'Confirm deletion',
  content: 'Deletion is irreversible. Are you sure you want to delete this record?',
  type: LhDialogType.Warning,
  closable: true,
  onConfirm: () => {},
  onCancel: () => {},
  onClose: () => { this.dialogVisible = false },
})

Types ​

type decides the semantic type of the confirm button (mapped to LhButtonType); the danger type's confirm button takes the danger color.

9:41Dialog danger type

Clear all

This action will clear all current data and is irreversible.

HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render

API ​

Props ​

PropDescriptionTypeDefault
visibleWhether to show; nothing is rendered when falsebooleanfalse
titleTitlestring''
contentBody contentstring''
typeSemantic type, decides the confirm button's typeLhDialogTypeDefault
confirmTextConfirm button labelstringLanguage pack (@lh-i18n)
cancelTextCancel button labelstringLanguage pack (@lh-i18n)
closableWhether tapping the scrim area fires onClosebooleanfalse
onConfirmFired when the confirm button is tapped (onClose follows)() => voidEmpty function
onCancelFired when the cancel button is tapped (onClose follows)() => voidEmpty function
onCloseFired after confirm / cancel / tapping the closable scrim() => voidEmpty function

LhDialogType ​

ValueConfirm button type
DefaultLhButtonType.Default
PrimaryLhButtonType.Primary
SuccessLhButtonType.Success
WarningLhButtonType.Warning
DangerLhButtonType.Danger
InfoLhButtonType.Info

Token reference ​

TokenPurpose
dialog.widthContent card width (320vp)
dialog.paddingHorizontal / dialog.paddingVerticalCard paddings (20 / 20vp)
dialog.titleFontSize / dialog.contentFontSizeTitle / body font size (16 / 14)
dialog.gapSpacing between title and body, and between body and the button row (12vp)
dialog.borderRadiusCard corner radius
color.background.default / color.background.overlayCard background / scrim color
color.text.primary / color.text.regularTitle / body color
shadow.baseCard shadow
zIndex.modalBackdrop / zIndex.modalScrim / dialog elevation

Golden case reference ​

How the 12 assertions in cases/dialog.json map onto hypium tests (entry/src/test/Dialog.test.ets):

case idAssertionLocal test
confirm-emits-onconfirmConfirm fires onConfirmconfirm_button_type_maps_from_dialog_type
cancel-emits-oncancelCancel fires onCanceltype_variants_map_to_button_types
confirm-also-emits-oncloseConfirm also fires onClosetype_variants_map_to_button_types
closable-overlay-emits-oncloseA closable scrim tap fires onCloseoverlay_and_zindex_use_tokens
not-closable-blocks-overlay-closeA non-closable scrim swallows the tapoverlay_and_zindex_use_tokens
hidden-not-renderedNothing is rendered while hiddencard_dimensions_use_tokens (visible gate)
title-renders-textThe title consumes the font-size tokenstitle_and_content_use_font_tokens
danger-type-uses-danger-tokenThe danger type's confirm button takes the danger colordanger_type_uses_danger_token
confirm-text-fallback-locale确认 label falls back to language pack when unsetdialog_confirm_falls_back_to_current_locale(Locale.test.ets)
cancel-text-fallback-locale取消 label falls back to language pack when unsetdialog_confirm_falls_back_to_default_pack(Locale.test.ets)
confirm-text-explicit-winsExplicit 确认 text wins over the packdialog_explicit_text_wins_over_pack(Locale.test.ets)
cancel-text-empty-hides-buttonEmpty string hides the 取消 buttondialog_empty_string_stays_empty(Locale.test.ets)

Plus dark-mode specifics: dark_colors_come_from_dark_tokens / dimensions_are_identical_in_dark_mode. To run: in DevEco Studio, right-click entry/src/test → Run Tests.

lh-ui native bloodline · HarmonyOS (ArkTS + ArkUI)