示例#1
0
        /// <summary>
        /// Method is called via EventCallBack if the keyboard key is no longer pressed inside the Input element.
        /// </summary>
        /// <param name="e">Contains the key (combination) which was pressed inside the Input element</param>
        protected async Task OnKeyDown(KeyboardEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            var key = e.Key.ToUpperInvariant();

            if (key == "ENTER" || key == "TAB" || key == "ESCAPE")
            {
                _duringManualInput = false;
                if (string.IsNullOrWhiteSpace(_inputStart.Value))
                {
                    ClearValue();
                }
                else
                {
                    await TryApplyInputValue();
                }

                if (key == "ESCAPE" && _dropDown.IsOverlayShow())
                {
                    Close();
                    await Js.FocusAsync(_inputStart.Ref);

                    return;
                }
                if (key == "ENTER")
                {
                    //needed only in wasm, details: https://github.com/dotnet/aspnetcore/issues/30070
                    await Task.Yield();

                    await Js.InvokeVoidAsync(JSInteropConstants.InvokeTabKey);
                }
                Close();
                AutoFocus = false;
                return;
            }

            if (key == "ARROWDOWN" && !_dropDown.IsOverlayShow())
            {
                await _dropDown.Show();

                return;
            }
            if (key == "ARROWUP" && _dropDown.IsOverlayShow())
            {
                Close();
                return;
            }
        }
示例#2
0
        /// <summary>
        /// Method is called via EventCallBack if the keyboard key is no longer pressed inside the Input element.
        /// </summary>
        /// <param name="e">Contains the key (combination) which was pressed inside the Input element</param>
        /// <param name="index">Refers to picker index - 0 for starting date, 1 for ending date</param>
        protected async Task OnKeyDown(KeyboardEventArgs e, int index)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            var key = e.Key.ToUpperInvariant();

            if (key == "ENTER" || key == "TAB" || key == "ESCAPE")
            {
                if (_duringManualInput)
                {
                    //A scenario when there are a lot of controls;
                    //It may happen that incorrect values were entered into one of the input
                    //followed by ENTER key. This event may be fired before input manages
                    //to get the value. Here we ensure that input will get that value.
                    await Task.Delay(5);

                    _duringManualInput = false;
                }
                var input = (index == 0 ? _inputStart : _inputEnd);
                if (string.IsNullOrWhiteSpace(input.Value))
                {
                    ClearValue(index, false);
                }
                else if (!await TryApplyInputValue(index, input.Value))
                {
                    return;
                }

                if (key == "ESCAPE" && _dropDown.IsOverlayShow())
                {
                    Close();
                    await Js.FocusAsync(input.Ref);

                    return;
                }

                if (index == 1)
                {
                    if (key != "TAB")
                    {
                        //needed only in wasm, details: https://github.com/dotnet/aspnetcore/issues/30070
                        await Task.Yield();

                        await Js.InvokeVoidAsync(JSInteropConstants.InvokeTabKey);

                        Close();
                    }
                    else if (!e.ShiftKey)
                    {
                        Close();
                        AutoFocus = false;
                    }
                }
                if (index == 0)
                {
                    if (key == "TAB" && e.ShiftKey)
                    {
                        Close();
                        AutoFocus = false;
                    }
                    else if (key != "TAB")
                    {
                        await Blur(0);
                        await Focus(1);
                    }
                }
                return;
            }
            if (key == "ARROWDOWN" && !_dropDown.IsOverlayShow())
            {
                await _dropDown.Show();

                return;
            }
            if (key == "ARROWUP" && _dropDown.IsOverlayShow())
            {
                Close();
                await Task.Yield();

                AutoFocus = true;
                return;
            }
        }