Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert committed Aug 23, 2023
1 parent 721bc9f commit 879fe7b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 7 deletions.
14 changes: 13 additions & 1 deletion inst/www/shared/shiny.js
Original file line number Diff line number Diff line change
Expand Up @@ -8804,7 +8804,7 @@
if (!$el.hasClass("symbol")) {
return null;
}
if ($el.attr("multiple") === "multiple") {
if (this._isMultipleSelect($el)) {
return "shiny.symbolList";
} else {
return "shiny.symbol";
Expand Down Expand Up @@ -8976,8 +8976,20 @@
control.destroy();
control = $el.selectize(settings)[0].selectize;
}
if (this._isMultipleSelect($el)) {
control.on("item_add", function() {
var input = control.$control_input;
if (input && input.length)
input[0].focus();
});
}
return control;
}
}, {
key: "_isMultipleSelect",
value: function _isMultipleSelect($el) {
return $el.attr("multiple") === "multiple";
}
}]);
return SelectInputBinding2;
}(InputBinding);
Expand Down
4 changes: 2 additions & 2 deletions inst/www/shared/shiny.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inst/www/shared/shiny.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions inst/www/shared/shiny.min.js.map

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion srcts/src/bindings/input/selectInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type SelectInputReceiveMessageData = {
type SelectizeOptions = Selectize.IOptions<string, unknown>;
type SelectizeInfo = Selectize.IApi<string, unknown> & {
settings: SelectizeOptions;
// eslint-disable-next-line @typescript-eslint/naming-convention
$control_input?: JQuery<HTMLElement>;
};

function getLabelNode(el: SelectHTMLElement): JQuery<HTMLElement> {
Expand Down Expand Up @@ -52,7 +54,7 @@ class SelectInputBinding extends InputBinding {
// default character type
return null;
}
if ($el.attr("multiple") === "multiple") {
if (this._isMultipleSelect($el)) {
return "shiny.symbolList";
} else {
return "shiny.symbol";
Expand Down Expand Up @@ -292,8 +294,22 @@ class SelectInputBinding extends InputBinding {
control.destroy();
control = $el.selectize(settings)[0].selectize as SelectizeInfo;
}

// (Hopefully temporary) workaround for a v0.15.2 selectize bug where the
// dropdown (instead of the <input>) gets focus after an item added via
// click. https://github.com/selectize/selectize.js/issues/2032
if (this._isMultipleSelect($el)) {
control.on("item_add", function () {
const input = control.$control_input;
if (input && input.length) input[0].focus();
});
}

return control;
}
protected _isMultipleSelect($el: JQuery<HTMLElement>): boolean {
return $el.attr("multiple") === "multiple";
}
}

export { SelectInputBinding };
Expand Down
1 change: 1 addition & 0 deletions srcts/types/src/bindings/input/selectInput.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type SelectInputReceiveMessageData = {
type SelectizeOptions = Selectize.IOptions<string, unknown>;
type SelectizeInfo = Selectize.IApi<string, unknown> & {
settings: SelectizeOptions;
$control_input: JQuery<HTMLElement>;
};
declare class SelectInputBinding extends InputBinding {
find(scope: HTMLElement): JQuery<HTMLElement>;
Expand Down

0 comments on commit 879fe7b

Please sign in to comment.