import com.vaadin.flow.component.Key; import com.vaadin.flow.component.KeyModifier; import com.vaadin.flow.component.button.Button; import com.vaadin.flow.component.ironlist.IronList; import com.vaadin.flow.component.ironlist.IronListDataView; import com.vaadin.flow.component.html.Span; import com.vaadin.flow.component.orderedlayout.VerticalLayout; import com.vaadin.flow.router.Route; @Route("accessibility-example") public class AccessibilityExample extends VerticalLayout { public AccessibilityExample() { IronList<String> list = new IronList<>(); IronListDataView<String> dataView = list.setItems(Arrays.asList("Item 1", "Item 2", "Item 3")); list.setRenderer((root, item) -> { Span span = new Span(item); root.appendChild(span.getElement()); }); list.addAttachListener(event -> { list.getElement().executeJs("component.addEventListener('keydown', function(event) { if (event.key === 'Enter') { window.alert('Enter key pressed'); } });"); }); Button alertButton = new Button("Show Alert"); alertButton.addClickShortcut(Key.ENTER, KeyModifier.CONTROL); alertButton.addClickListener(event -> { list.selectNext(); list.focus(); }); add(list, alertButton); } }


上一篇:
下一篇:
切换中文