UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

123 lines (122 loc) 5.36 kB
/** * DevExtreme (esm/__internal/ui/drop_down_editor/m_drop_down_button.js) * Version: 25.2.5 * Build date: Fri Feb 20 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import eventsEngine from "../../../common/core/events/core/events_engine"; import messageLocalization from "../../../common/core/localization/message"; import $ from "../../../core/renderer"; import { extend } from "../../../core/utils/extend"; import Button from "../../../ui/button"; import TextEditorButton from "../text_box/texteditor_button_collection/button"; const DROP_DOWN_EDITOR_BUTTON_CLASS = "dx-dropdowneditor-button"; const DROP_DOWN_EDITOR_BUTTON_VISIBLE = "dx-dropdowneditor-button-visible"; const BUTTON_MESSAGE = "dxDropDownEditor-selectLabel"; export default class DropDownButton extends TextEditorButton { constructor(name, editor, options) { super(name, editor, options); this.currentTemplate = null } _attachEvents(instance) { instance.option("onClick", (e => { var _this$editor, _this$editor$_shouldC, _this$editor3; if (null !== (_this$editor = this.editor) && void 0 !== _this$editor && null !== (_this$editor$_shouldC = _this$editor._shouldCallOpenHandler) && void 0 !== _this$editor$_shouldC && _this$editor$_shouldC.call(_this$editor)) { var _this$editor2; null === (_this$editor2 = this.editor) || void 0 === _this$editor2 || _this$editor2._openHandler(e); return } const { openOnFieldClick: openOnFieldClick } = (null === (_this$editor3 = this.editor) || void 0 === _this$editor3 ? void 0 : _this$editor3.option()) ?? {}; if (!openOnFieldClick) { var _this$editor4; null === (_this$editor4 = this.editor) || void 0 === _this$editor4 || _this$editor4._openHandler(e) } })); eventsEngine.on(instance.$element(), "mousedown", (e => { var _this$editor5; if (null !== (_this$editor5 = this.editor) && void 0 !== _this$editor5 && _this$editor5.$element().is(".dx-state-focused")) { e.preventDefault() } })) } _create() { const { editor: editor } = this; if (!editor) { return } const $element = $("<div>"); const options = this._getOptions(); this._addToContainer($element); const instance = editor._createComponent($element, Button, extend({}, options, { elementAttr: { "aria-label": messageLocalization.format(BUTTON_MESSAGE) } })); this._legacyRender(editor.$element(), $element, options.visible); return { $element: $element, instance: instance } } _getOptions() { const { editor: editor } = this; const visible = this._isVisible(); const isReadOnly = null === editor || void 0 === editor ? void 0 : editor.option("readOnly"); const options = { focusStateEnabled: false, hoverStateEnabled: false, activeStateEnabled: false, useInkRipple: false, disabled: isReadOnly, visible: visible }; this._addTemplate(options); return options } _isVisible() { const { editor: editor } = this; return super._isVisible() && (null === editor || void 0 === editor ? void 0 : editor.option("showDropDownButton")) } _legacyRender($editor, $element, isVisible) { $editor.toggleClass(DROP_DOWN_EDITOR_BUTTON_VISIBLE, isVisible); if ($element) { $element.removeClass("dx-button").removeClass("dx-button-mode-contained").addClass("dx-dropdowneditor-button") } } _isSameTemplate() { var _this$editor6; return (null === (_this$editor6 = this.editor) || void 0 === _this$editor6 ? void 0 : _this$editor6.option("dropDownButtonTemplate")) === this.currentTemplate } _addTemplate(options) { if (!this._isSameTemplate()) { var _this$editor7, _this$editor8; options.template = null === (_this$editor7 = this.editor) || void 0 === _this$editor7 ? void 0 : _this$editor7._getTemplateByOption("dropDownButtonTemplate"); this.currentTemplate = null === (_this$editor8 = this.editor) || void 0 === _this$editor8 ? void 0 : _this$editor8.option("dropDownButtonTemplate") } } update() { const shouldUpdate = super.update(); if (shouldUpdate) { const { editor: editor, instance: instance } = this; const $editor = null === editor || void 0 === editor ? void 0 : editor.$element(); const options = this._getOptions(); null === instance || void 0 === instance || instance.option(options); this._legacyRender($editor, null === instance || void 0 === instance ? void 0 : instance.$element(), options.visible) } } }