Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Use CSS to specify field cursors. #8648

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions core/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,4 +478,17 @@ input[type=number] {
z-index: 80;
pointer-events: none;
}

.blocklyField {
cursor: default;
}

.blocklyInputField {
cursor: text;
}

.blocklyDragging .blocklyField,
.blocklyDragging .blocklyIconGroup {
cursor: grabbing;
}
`;
5 changes: 0 additions & 5 deletions core/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,6 @@ export abstract class Field<T = any>
*/
SERIALIZABLE = false;

/** Mouse cursor style when over the hotspot that initiates the editor. */
CURSOR = '';

/**
* @param value The initial value of the field.
* Also accepts Field.SKIP_SETUP if you wish to skip setup (only used by
Expand Down Expand Up @@ -536,11 +533,9 @@ export abstract class Field<T = any>
if (this.enabled_ && block.isEditable()) {
dom.addClass(group, 'blocklyEditableField');
dom.removeClass(group, 'blocklyNonEditableField');
group.style.cursor = this.CURSOR;
} else {
dom.addClass(group, 'blocklyNonEditableField');
dom.removeClass(group, 'blocklyEditableField');
group.style.cursor = '';
}
}

Expand Down
5 changes: 0 additions & 5 deletions core/field_checkbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ export class FieldCheckbox extends Field<CheckboxBool> {
*/
override SERIALIZABLE = true;

/**
* Mouse cursor style when over the hotspot that initiates editability.
*/
override CURSOR = 'default';

/**
* NOTE: The default value is set in `Field`, so maintain that value instead
* of overwriting it here or in the constructor.
Expand Down
8 changes: 5 additions & 3 deletions core/field_dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ export class FieldDropdown extends Field<string> {
*/
override SERIALIZABLE = true;

/** Mouse cursor style when over the hotspot that initiates the editor. */
override CURSOR = 'default';

protected menuGenerator_?: MenuGenerator;

/** A cache of the most recently generated options. */
Expand Down Expand Up @@ -204,6 +201,11 @@ export class FieldDropdown extends Field<string> {
if (this.borderRect_) {
dom.addClass(this.borderRect_, 'blocklyDropdownRect');
}

if (this.fieldGroup_) {
dom.addClass(this.fieldGroup_, 'blocklyField');
dom.addClass(this.fieldGroup_, 'blocklyDropdownField');
}
}

/**
Expand Down
7 changes: 4 additions & 3 deletions core/field_input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,6 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
*/
override SERIALIZABLE = true;

/** Mouse cursor style when over the hotspot that initiates the editor. */
override CURSOR = 'text';

/**
* @param value The initial value of the field. Should cast to a string.
* Defaults to an empty string if null or undefined. Also accepts
Expand Down Expand Up @@ -148,6 +145,10 @@ export abstract class FieldInput<T extends InputTypes> extends Field<
if (this.isFullBlockField()) {
this.clickTarget_ = (this.sourceBlock_ as BlockSvg).getSvgRoot();
}

if (this.fieldGroup_) {
dom.addClass(this.fieldGroup_, 'blocklyInputField');
}
}

protected override isFullBlockField(): boolean {
Expand Down
Loading