createHtmlElement method

  1. @override
WebHTMLElement? createHtmlElement()
override

Creates and returns a WebHTMLElement to represent this object in the DOM.

Returns null if no element should be created.

Implementation

@override
WebHTMLElement? createHtmlElement() {
  // Only create HTML element if running on the web
  if (!kIsWeb) return null;

  // Create a native HTML <button> element
  final button = webWindow.document.createElement('button') as WebHTMLElement;
  button.textContent = label;

  // Set the HTML id attribute (for SEO and DOM access)
  button.id = id ?? _generateRandomId();

  // Optional: Add ARIA role for better accessibility
  button.setAttribute('role', 'button');

  return button;
}