Search in sources :

Example 11 with KeyboardEvent

use of elemental2.dom.KeyboardEvent in project kie-wb-common by kiegroup.

the class ValueAndDataTypePopoverViewImpl method typeSelectorKeyDownEventListener.

void typeSelectorKeyDownEventListener(final Object event) {
    if (event instanceof KeyboardEvent) {
        final KeyboardEvent keyEvent = (KeyboardEvent) event;
        if (isEnterKeyPressed(keyEvent)) {
            hide(true);
            keyEvent.preventDefault();
            onClosedByKeyboard();
        } else if (isEscapeKeyPressed(keyEvent)) {
            reset();
            hide(false);
            onClosedByKeyboard();
        } else if (isTabKeyPressed(keyEvent)) {
            if (keyEvent.shiftKey) {
                final Button manageButton = getManageButton();
                manageButton.focus();
            } else {
                valueEditor.focus();
            }
            keyEvent.preventDefault();
        }
    }
}
Also used : Button(org.jboss.errai.common.client.dom.Button) KeyboardEvent(elemental2.dom.KeyboardEvent)

Example 12 with KeyboardEvent

use of elemental2.dom.KeyboardEvent in project kie-wb-common by kiegroup.

the class ValueAndDataTypePopoverViewImplTest method testTypeSelectorKeyDownEventListenerEscKey.

@Test
public void testTypeSelectorKeyDownEventListenerEscKey() {
    final KeyboardEvent keyboardEvent = mock(KeyboardEvent.class);
    doReturn(false).when(view).isEnterKeyPressed(keyboardEvent);
    doReturn(true).when(view).isEscapeKeyPressed(keyboardEvent);
    final ValueAndDataTypePopoverViewImpl.BootstrapSelectDropDownMonitor monitor = mock(ValueAndDataTypePopoverViewImpl.BootstrapSelectDropDownMonitor.class);
    doReturn(monitor).when(view).getMonitor();
    final elemental2.dom.Element menuElement = mock(elemental2.dom.Element.class);
    doReturn(menuElement).when(monitor).getMenuElement();
    view.typeSelectorKeyDownEventListener(keyboardEvent);
    verify(view).reset();
    verify(view).hide(false);
    verify(view).onClosedByKeyboard();
}
Also used : KeyboardEvent(elemental2.dom.KeyboardEvent) Test(org.junit.Test)

Example 13 with KeyboardEvent

use of elemental2.dom.KeyboardEvent in project kie-wb-common by kiegroup.

the class ValueAndDataTypePopoverViewImplTest method testIsEscapeKeyPressed.

@Test
public void testIsEscapeKeyPressed() {
    final KeyboardEvent keyboardEvent = mock(KeyboardEvent.class);
    keyboardEvent.key = ESC_KEY;
    boolean actual = view.isEscapeKeyPressed(keyboardEvent);
    assertTrue(actual);
    keyboardEvent.key = "A";
    actual = view.isEscapeKeyPressed(keyboardEvent);
    assertFalse(actual);
    keyboardEvent.key = ESCAPE_KEY;
    actual = view.isEscapeKeyPressed(keyboardEvent);
    assertTrue(actual);
}
Also used : KeyboardEvent(elemental2.dom.KeyboardEvent) Test(org.junit.Test)

Example 14 with KeyboardEvent

use of elemental2.dom.KeyboardEvent in project kie-wb-common by kiegroup.

the class ValueAndDataTypePopoverViewImplTest method testIsEnterKeyPressed.

@Test
public void testIsEnterKeyPressed() {
    final KeyboardEvent keyboardEvent = mock(KeyboardEvent.class);
    keyboardEvent.key = ENTER_KEY;
    boolean actual = view.isEnterKeyPressed(keyboardEvent);
    assertTrue(actual);
    keyboardEvent.key = "A";
    actual = view.isEnterKeyPressed(keyboardEvent);
    assertFalse(actual);
}
Also used : KeyboardEvent(elemental2.dom.KeyboardEvent) Test(org.junit.Test)

Example 15 with KeyboardEvent

use of elemental2.dom.KeyboardEvent in project kie-wb-common by kiegroup.

the class ValueAndDataTypePopoverViewImplTest method testManagerButtonKeyDownEventWhenIsNotEscapeKey.

@Test
public void testManagerButtonKeyDownEventWhenIsNotEscapeKey() {
    final KeyboardEvent keyboardEvent = mock(KeyboardEvent.class);
    doReturn(false).when(view).isEscapeKeyPressed(keyboardEvent);
    view.manageButtonKeyDownEventListener(keyboardEvent);
    verify(view, never()).hide(false);
    verify(view, never()).reset();
    verify(view, never()).onClosedByKeyboard();
}
Also used : KeyboardEvent(elemental2.dom.KeyboardEvent) Test(org.junit.Test)

Aggregations

KeyboardEvent (elemental2.dom.KeyboardEvent)21 Test (org.junit.Test)16 Event (org.jboss.errai.common.client.dom.Event)2 Button (org.jboss.errai.common.client.dom.Button)1