Summon provides comprehensive support for building accessible web applications and optimizing them for search engines. This guide covers the built-in accessibility and SEO features.
Summon provides extensive ARIA (Accessible Rich Internet Applications) support through modifiers:
Text(
text = "Accessible Text",
modifier = Modifier()
.role("heading")
.ariaLabel("Section heading")
.ariaDescribedBy("text-description")
)
Available ARIA modifiers include:
role() - Sets the ARIA roleariaLabel() - Sets the accessible nameariaLabelledBy() - References an element that labels this elementariaDescribedBy() - References an element that describes this elementariaHidden() - Hides content from screen readersariaExpanded() - Indicates if a control is expandedariaPressed() - Indicates if a button is pressedariaChecked() - Indicates if a checkbox/radio is checkedariaSelected() - Indicates if an option is selectedariaDisabled() - Indicates if an element is disabledariaInvalid() - Indicates if an input is invalidariaRequired() - Indicates if an input is requiredariaCurrent() - Indicates the current item in a setariaLive() - Sets the live region behaviorariaControls() - Indicates which element is controlled by the current elementariaHasPopup() - Indicates whether the element has a popupariaBusy() - Indicates that an element is being modifiedSummon includes utilities for managing keyboard focus:
// Make an element focusable but not in tab order
modifier.focusable()
// Make an element tabbable
modifier.tabbable()
// Disable focus
modifier.disabled()
// Auto-focus an element
modifier.autoFocus()
Summon provides an AccessibleElement wrapper component for easily adding accessibility attributes:
AccessibleElement(
role = AccessibilityUtils.NodeRole.ALERT,
label = "Important alert message",
relations = mapOf("describedby" to "alert-description"),
modifier = Modifier.color("#c62828")
) {
Text("Warning: This action cannot be undone")
}
The AccessibilityUtils object provides helpful functions to create and inspect accessibility attributes:
// Create a modifier with a specific role
val buttonModifier = AccessibilityUtils.createRoleModifier(AccessibilityUtils.NodeRole.BUTTON)
// Create a modifier with an accessible label
val labelModifier = AccessibilityUtils.createLabelModifier("Close dialog")
// Create a modifier with relationship to another element
val relationModifier = AccessibilityUtils.createRelationshipModifier("describedby", "description-id")
// Inspect accessibility attributes on a modifier
val modifier = Modifier()
.role("button")
.ariaLabel("Close")
val accessibilityAttrs = modifier.inspectAccessibility()
// Result: {"role": "button", "aria-label": "Close"}
Summon provides semantic HTML components for better accessibility:
Header {
Heading(level = 1) {
Text("Site Title")
}
}
Main {
Section {
Heading(level = 2) {
Text("About Us")
}
Text("Company information goes here")
}
Article {
Heading(level = 2) {
Text("Latest News")
}
Text("News content goes here")
}
}
Footer {
Text("© 2023 My Company")
}
Summon provides components for managing meta tags:
MetaTags(
title = "My Website",
description = "A description of my website",
keywords = "summon, ui, web framework",
author = "Your Name"
)
For better social media sharing:
OpenGraphTags(
title = "My Website",
type = "website",
url = "https://example.com",
image = "https://example.com/image.jpg",
description = "A description for social media",
siteName = "My Site"
)
For Twitter-specific metadata:
TwitterCards(
card = TwitterCards.CardType.SUMMARY_LARGE_IMAGE,
title = "My Website",
description = "A description for Twitter",
image = "https://example.com/image.jpg",
site = "@myhandle"
)
For managing duplicate content:
CanonicalLinks(
url = "https://example.com/page",
alternateLanguages = mapOf(
"en" to "https://example.com/page",
"es" to "https://example.com/es/page"
)
)
For rich search results:
StructuredData.webPage(
name = "Product Page",
description = "Our best product details",
url = "https://example.com/products/1"
)
StructuredData.organization(
name = "Example Company",
url = "https://example.com",
logo = "https://raw.githubusercontent.com/codeyousef/summon/main/assets/logo.png"
)
StructuredData.product(
name = "Example Product",
description = "This is our featured product",
image = "https://example.com/product1.jpg",
price = "99.99",
currency = "USD"
)
Summon supports deep linking with SEO-friendly URLs:
DeepLinking.generateMetaTags(
path = "/products/1",
title = "Product Details",
description = "View our featured product",
imageUrl = "https://example.com/product1.jpg"
)
Accessibility:
SEO: