JSFiddle - React, Tailwind, and code Playground

HTML

<select id="mySelect" multiple>
    <option>A</option>
    <option>B</option>
    <option>C</option>
    <option>D</option>
</select>

JavaScript

$("select").on("click", "option", function (event) {
    if (3 <= $(this).siblings(":selected").length) {
        $(this).removeAttr("selected");
    }
});